Hex / Binary / Octal / Decimal Converter

Convert numbers between hexadecimal, binary, octal, and decimal. Shows the bit pattern grouped by nibble + the two’s-complement representation for negative values.

Inputs

Type the number in the base selected below. Prefixes 0x / 0b / 0o are accepted and override the dropdown. Negative values allowed.

Base the value is written in. Ignored when the input has a 0x / 0b / 0o prefix.

Used to compute the two’s-complement representation for negative values and the unsigned wrap-around.

Result

Loading calculator…

How to use this calculator

  • Type the number in any of the four supported bases. Prefixes 0x, 0b, 0o are auto-detected.
  • Pick the base of the input if you are not using a prefix.
  • Choose the bit width that matches the integer type you care about (uint8, int32, etc.).
  • Read the four equivalent representations under the result. The binary is grouped per nibble for legibility.
  • Negative numbers show both the signed decimal value and the unsigned two’s-complement bit pattern.

About this calculator

Programmers, embedded engineers, and CTF players all spend a surprising amount of time translating between number bases. This converter handles the four bases you actually see in code — binary, octal, decimal, hexadecimal — and also shows the two’s-complement representation at 8/16/32/64-bit widths so you can sanity-check negative integers, bitmask values, and sign-extension behavior. The 0x / 0b / 0o prefixes are auto-detected, so you can paste a value straight from source code without first stripping the prefix. Underscores, commas, and whitespace are tolerated as group separators (handy for long binary masks). Negative inputs return both the signed decimal value and the unsigned bit pattern at the chosen width.

How it works — the formula

value₁₀ = Σ (digitᵢ × baseⁱ) two’s-complement(−n, N bits) = 2ᴺ − n

A positional numeral system encodes a value as a weighted sum of digits where each weight is the base raised to that digit’s position. Two’s complement is the dominant binary signed-integer encoding because subtraction and overflow detection collapse to the same circuitry as unsigned addition.

Worked examples

Example 1
Hex → decimal
Inputs:
value = FF, fromBase = 16
Output:
decimal 255, binary 0b 0000 0000 0000 0000 0000 0000 1111 1111
Example 2
Decimal → binary (negative, 8-bit)
Inputs:
value = −1, fromBase = 10, width = 8
Output:
hex 0xFF, binary 0b 1111 1111 (two’s complement)
Example 3
Binary → hex
Inputs:
value = 1010_1100, fromBase = 2
Output:
hex 0xAC, decimal 172

Limitations

  • Integer-only — no IEEE-754 float bit-pattern decoding.
  • When the input exceeds the selected bit width, the hex/octal/binary columns wrap to the unsigned mask of that width; the decimal column keeps the exact value.
  • Hex output is uppercased; lowercase output is not configurable.

BigInt-backed conversions: results are exact for any input size that fits in your browser’s memory. Bit-width selection only affects the masked unsigned representation, not the decimal output.

Frequently asked

How do I convert hexadecimal to decimal?+
Each hex digit represents a power of 16. Multiply each digit by 16 raised to its position (rightmost = 16⁰, next = 16¹, ...) and sum the results. For example 0xFF = 15×16¹ + 15×16⁰ = 240 + 15 = 255. This calculator does the arithmetic for you using BigInt so the result is exact at any size.
What is two’s complement?+
Two’s complement is the standard way computers store signed integers. To represent −n in N bits, take the unsigned value 2ᴺ − n. For an int8, −1 is stored as 0xFF, −2 as 0xFE, and so on. This is why integer overflow wraps cleanly and why a single ADD instruction works for both signed and unsigned arithmetic.
Why does my hex value have leading zeros?+
The hex output is zero-padded to the bit width you chose, so a 32-bit value always shows 8 hex digits. This makes byte-level comparison (e.g. lining up two MAC addresses or PCI IDs) much easier. Switch to a smaller bit width if you want the shortest unpadded representation.
Can I paste a value with underscores or spaces?+
Yes. Underscores (Rust / Python literals), commas (thousand separators), and whitespace are all stripped before parsing. So 0b1111_0000, 0xDEAD_BEEF, and 1,048,576 are all valid inputs.
What happens if the value is bigger than the selected bit width?+
The decimal output keeps the exact value (BigInt-backed, so there is no precision loss). The hex, octal, and binary columns are computed against an unsigned mask of the chosen width — so they wrap, exactly the way the corresponding C cast would.
Does this calculator handle floating-point bit patterns?+
No — this tool is integer-only. For IEEE 754 single/double bit-pattern inspection use a dedicated float-to-hex calculator. Integer base conversion is the workhorse you reach for when reading register dumps, MAC addresses, RGB color values, or bitmask constants.

Related calculators

More tools you might like

Hand-picked tools that pair well with this one — same audience, same intent.