Skip to content

Binary, octal, decimal and hex converter

Convert numbers between binary, octal, decimal, hex, base36 and any base from 2 to 36, with bitwise operations, byte grouping and a two’s-complement view.

  • Runs in your browser
  • Nothing you enter is sent
  • Free, no account
Number to convert
Conversion uses BigInt, so 64-bit ids and 256-bit hashes convert exactly — no floating-point rounding.

Underscores, spaces and the 0x / 0b / 0o prefixes are ignored. A decimal point is allowed.

BaseValueCopy
Binary(2)11111111
Octal(8)377
Decimal(10)255
Hexadecimal(16)ff
Base 36(36)73
Base 12(12)193
Digits (base 10)
3
Bits set
8
Fits in
8 bits
Machine representation
How the integer part is stored in a fixed-width register, including the two's-complement signed reading.
Unsigned255
Signed (two's complement)255
Hexadecimal0x0000 00FF
Binary00000000 00000000 00000000 11111111
Sign bit0 — positive when read as a signed integer
Bitwise calculator
Operations are evaluated at the register width chosen above, then shown in every base.

A bit is 1 only when it is 1 in both operands

Result (decimal)15
Hexadecimal0x0000000F
Binary00000000 00000000 00000000 00001111

How to convert between bases

  1. Enter the number and tell the tool which base it is written in. Prefixes such as 0x, 0b and 0o are stripped automatically, and underscores or spaces used as digit separators are ignored.
  2. Binary, octal, decimal, hexadecimal and base 36 are produced at once; add any other base from 2 to 36 in the extra field.
  3. Pick a register width to see the two's-complement representation the hardware would actually store.
  4. Use the bitwise calculator for AND, OR, XOR, NOT and the three shift operators, evaluated at that width.

Why BigInt matters here

JavaScript numbers are IEEE-754 doubles, which represent integers exactly only up to 253 − 1 — about 9.007 quadrillion. Beyond that, values silently round: a converter built on parseInt will turn a 64-bit database identifier or a 256-bit hash into a nearby but wrong number without any warning. Everything on this page uses BigInt, so a 512-bit value converts digit for digit with no loss.

Base reference

BaseNameDigitsWhere you meet it
2Binary0-1Bit flags, masks, hardware registers
8Octal0-7Unix file permissions (chmod 755)
10Decimal0-9Everything human
16Hexadecimal0-9, a-fMemory addresses, colours, hashes, byte dumps
32Base320-9, a-vCase-insensitive identifiers
36Base360-9, a-zShort URL slugs and compact ids

Hexadecimal is popular for one reason: 16 is 24, so each hex digit maps to exactly four bits and conversion to binary is a lookup with no arithmetic. Two hex digits are exactly one byte, which is why every hex dump in existence is grouped in pairs.

Two's complement in one paragraph

Computers store negative integers by reserving the top bit and defining the negative of a value as "flip every bit, then add one". In eight bits, 0000 0001 is 1 and 1111 1111 is −1. The clever part is that ordinary binary addition then works for both signs with no special case, which is why essentially every processor uses it. The consequences are visible in the panel above: the range is asymmetric (−128 to +127 in eight bits, because zero occupies a slot on the positive side), and the same bit pattern reads as 255 unsigned or −1 signed depending only on how you interpret it.

WidthUnsigned rangeSigned range
8-bit0 … 255−128 … 127
16-bit0 … 65,535−32,768 … 32,767
32-bit0 … 4,294,967,295−2,147,483,648 … 2,147,483,647
64-bit0 … 18,446,744,073,709,551,615−9,223,372,036,854,775,808 … 9,223,372,036,854,775,807

The bitwise operators

OperatorSymbolTypical use
ANDa & bTest a flag, or mask off unwanted bits: value & 0xFF keeps the low byte
ORa | bSet a flag without disturbing the others
XORa ^ bToggle a flag; also finds which bits differ between two values
NOT~aBuild an inverse mask
Shift lefta << nMultiply by 2n; build a mask with 1 << n
Arithmetic shift righta >> nDivide a signed value by 2n, keeping the sign
Logical shift righta >>> nDivide an unsigned value, filling with zeros from the left

Note that JavaScript's own bitwise operators coerce their operands to 32-bit signed integers, so 2 ** 40 | 0 gives 0 in a browser console. The calculator here works at the width you choose, which is why its answers can differ from a quick check in devtools.

Fractions

A fractional part is supported and is converted exactly, as a rational number, rather than through a floating-point intermediate. 0.1 in decimal becomes the repeating expansion 0.0001100110011… in binary — which is precisely why 0.1 + 0.2 is not 0.3 in any language that uses binary floating point. Output is truncated after 20 fractional digits.

Questions

How big a number can it convert?

Arbitrarily big. Conversion uses BigInt, so 256-bit hashes and 64-bit identifiers convert exactly with no floating-point rounding, unlike tools built on JavaScript numbers.

How does the two’s-complement view work?

Pick a width of 8, 16, 32 or 64 bits and the value is shown as the machine would store it, including the signed interpretation and the wrapped value if the number does not fit.

Which bitwise operations are available?

AND, OR, XOR, NOT, left shift, arithmetic right shift and logical right shift, all evaluated at the chosen width with the result shown in every base at once.

Can I convert negative or fractional values?

Negative integers, yes — enter a leading minus sign, and the two’s-complement panel shows the machine representation. Fractional values are supported for decimal and for power-of-two bases up to 16 digits after the point.

Why is my hex value rejected?

Each base only allows its own digits: base 2 takes 0 and 1, base 16 takes 0-9 and a-f. The error names the first invalid character and its position, and prefixes such as 0x, 0b and 0o are stripped automatically.