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
Underscores, spaces and the 0x / 0b / 0o prefixes are ignored. A decimal point is allowed.
| Base | Value | Copy |
|---|---|---|
| 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
| Unsigned | 255 |
| Signed (two's complement) | 255 |
| Hexadecimal | 0x0000 00FF |
| Binary | 00000000 00000000 00000000 11111111 |
| Sign bit | 0 — positive when read as a signed integer |
A bit is 1 only when it is 1 in both operands
| Result (decimal) | 15 | |
| Hexadecimal | 0x0000000F | |
| Binary | 00000000 00000000 00000000 00001111 |
How to convert between bases
- Enter the number and tell the tool which base it is written in. Prefixes such as
0x,0band0oare stripped automatically, and underscores or spaces used as digit separators are ignored. - Binary, octal, decimal, hexadecimal and base 36 are produced at once; add any other base from 2 to 36 in the extra field.
- Pick a register width to see the two's-complement representation the hardware would actually store.
- 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
| Base | Name | Digits | Where you meet it |
|---|---|---|---|
| 2 | Binary | 0-1 | Bit flags, masks, hardware registers |
| 8 | Octal | 0-7 | Unix file permissions (chmod 755) |
| 10 | Decimal | 0-9 | Everything human |
| 16 | Hexadecimal | 0-9, a-f | Memory addresses, colours, hashes, byte dumps |
| 32 | Base32 | 0-9, a-v | Case-insensitive identifiers |
| 36 | Base36 | 0-9, a-z | Short 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.
| Width | Unsigned range | Signed range |
|---|---|---|
| 8-bit | 0 … 255 | −128 … 127 |
| 16-bit | 0 … 65,535 | −32,768 … 32,767 |
| 32-bit | 0 … 4,294,967,295 | −2,147,483,648 … 2,147,483,647 |
| 64-bit | 0 … 18,446,744,073,709,551,615 | −9,223,372,036,854,775,808 … 9,223,372,036,854,775,807 |
The bitwise operators
| Operator | Symbol | Typical use |
|---|---|---|
| AND | a & b | Test a flag, or mask off unwanted bits: value & 0xFF keeps the low byte |
| OR | a | b | Set a flag without disturbing the others |
| XOR | a ^ b | Toggle a flag; also finds which bits differ between two values |
| NOT | ~a | Build an inverse mask |
| Shift left | a << n | Multiply by 2n; build a mask with 1 << n |
| Arithmetic shift right | a >> n | Divide a signed value by 2n, keeping the sign |
| Logical shift right | a >>> n | Divide 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.