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

Decimal
255
Value fits in 8 bits.
  • Hexadecimal32-bit, zero-padded.0x00 00 00 FF
  • Octal0o377
  • Binary32-bit, grouped per nibble.0b0000 0000 0000 0000 0000 0000 1111 1111
  • Bit width chosen32-bit
  • Fits in signed range?Yes
Note — Values larger than the selected bit width are still converted; the unsigned column wraps to the chosen width while the decimal column keeps the exact value.

Step-by-step

  1. Read the input as base-16: FF (sign positive).
  2. Decimal value: 255.
  3. Apply the 32-bit two’s-complement mask (& 0xFFFFFFFF).
  4. Hex: 0x000000FF Octal: 0o377 Binary (grouped per nibble): 0b 0000 0000 0000 0000 0000 0000 1111 1111.

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

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.

Related calculators

More tools you might like