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.
Result
- 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
Step-by-step
- Read the input as base-16: FF (sign positive).
- Decimal value: 255.
- Apply the 32-bit two’s-complement mask (& 0xFFFFFFFF).
- 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ᴺ − nA 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
- Inputs:
- value = FF, fromBase = 16
- Output:
- decimal 255, binary 0b 0000 0000 0000 0000 0000 0000 1111 1111
- Inputs:
- value = −1, fromBase = 10, width = 8
- Output:
- hex 0xFF, binary 0b 1111 1111 (two’s complement)
- 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.