Number Base Converter (Decimal, Binary, Hex, Octal)
Convert a whole number between binary, octal, decimal, and hexadecimal. Negative numbers and arbitrarily large values are supported without precision loss. Everything runs in your browser.
How positional notation works
Every base uses the same idea: each digit position carries a weight that is a power of the base. In decimal, 253 means 2×10² + 5×10¹ + 3×10⁰.
Binary works identically with powers of two. The binary number
1101 is:
1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13
Converting the other way, divide repeatedly by the target base and read
the remainders backwards. For 13 to binary: 13÷2 = 6 r1, 6÷2 = 3 r0,
3÷2 = 1 r1, 1÷2 = 0 r1. Reading the remainders in reverse gives
1101.
Bases above 10 need extra digit symbols, so letters take over: in
hexadecimal, a through f represent 10 through 15.
Why hexadecimal is everywhere in computing
Hex is not arbitrary. It exists because 16 is 2⁴, which means one hex digit corresponds to exactly four binary digits, with no carrying between them.
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | a | 1010 |
| 3 | 0011 | b | 1011 |
| 4 | 0100 | c | 1100 |
| 5 | 0101 | d | 1101 |
| 6 | 0110 | e | 1110 |
| 7 | 0111 | f | 1111 |
This makes hex-to-binary conversion a lookup rather than arithmetic. The
byte 11010110 splits into 1101 and
0110, which are d and 6, so the byte is
d6. One byte is always exactly two hex digits, which is why
memory dumps, colour codes, and MAC addresses all use hex.
Octal (base 8) has the same property with three bits per digit. It was
common on older systems with 12-bit and 36-bit words but survives today
mainly in Unix file permissions, where 755 encodes three groups
of three permission bits.
Examples
| Decimal | Binary | Octal | Hex | Note |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 10 | 1010 | 12 | a | |
| 15 | 1111 | 17 | f | Largest single hex digit |
| 16 | 10000 | 20 | 10 | Hex rolls over |
| 255 | 11111111 | 377 | ff | Largest single byte |
| 1024 | 10000000000 | 2000 | 400 | 210 |
| 65535 | 1111111111111111 | 177777 | ffff | Largest 16-bit value |
Where each base shows up
Hex in colours
CSS colours like #ff8800 are three bytes: red, green, blue,
each 0 to 255 written as two hex digits. ff is 255 (maximum),
00 is zero. For working with colour values directly, see the
colour converter.
Octal in file permissions
Unix chmod 755 uses octal because each digit maps to exactly
three permission bits: read (4), write (2), execute (1). The digit 7 is
4+2+1, meaning all three, and 5 is 4+1, meaning read and execute. So 755 is
full access for the owner, read and execute for everyone else.
Binary in flags and masks
Bit flags pack several booleans into one integer, each bit representing one option. Checking a flag uses a bitwise AND with a mask. Viewing the value in binary makes it immediately clear which bits are set, which is far harder to see in decimal.
Hex in memory addresses and debugging
Memory addresses, stack traces, and hex dumps use base 16 because the
byte boundaries stay visible. The address 0x7fff5fbff8c0 is
unreadable in decimal but its structure is apparent in hex.
Notation prefixes
Most languages mark the base with a prefix, since 101 alone is
ambiguous:
| Prefix | Base | Example | Decimal value |
|---|---|---|---|
0b | Binary | 0b1010 | 10 |
0o or leading 0 | Octal | 0o17 | 15 |
0x | Hexadecimal | 0xff | 255 |
| none | Decimal | 42 | 42 |
A historical trap: in C and several languages that follow it, a plain
leading zero means octal. So 010 is 8, not 10. This has caused
enough bugs that newer languages require the explicit 0o form.
Frequently asked questions
Are negative numbers supported?
Yes, prefix the input with -. Note that this is a signed
representation, not two's complement, which is how negative numbers are
actually stored in hardware.
What happens with a digit invalid for the source base?
You get a clear error message. Entering 2 while converting
from binary, or g from hexadecimal, is rejected rather than
silently misparsed.
Can it handle very large numbers?
Yes. Conversion uses BigInt, so there is no precision loss even far beyond the 253 limit of ordinary JavaScript numbers.
Why is hexadecimal used instead of binary?
Because one hex digit equals exactly four bits, so hex is a compact shorthand for binary that stays aligned to byte boundaries. A 32-bit value is 8 hex digits instead of 32 binary ones.
What does 0x mean?
It is the conventional prefix marking a hexadecimal literal, used in C,
Java, JavaScript, Python, C#, and many others. 0xff is 255.
Does this handle decimal fractions?
No, only whole numbers. Fractional values in other bases raise separate representation questions, and binary cannot represent many decimal fractions exactly, which is a different topic from integer base conversion.
Related tools
- Subnet calculator, which relies on binary network masks
- Colour converter, for hex colour values
- Data size converter, for powers of two in storage units
- All developer tools