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.

HexBinaryHexBinary
0000081000
1000191001
20010a1010
30011b1011
40100c1100
50101d1101
60110e1110
70111f1111

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

DecimalBinaryOctalHexNote
0000
10101012a
15111117fLargest single hex digit
16100002010Hex rolls over
25511111111377ffLargest single byte
1024100000000002000400210
655351111111111111111177777ffffLargest 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:

PrefixBaseExampleDecimal value
0bBinary0b101010
0o or leading 0Octal0o1715
0xHexadecimal0xff255
noneDecimal4242

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