The same number can be written in different bases, and programming throws all of them at you. Decimal is what we count in, but binary, hex, and octal show up in colors, memory addresses, file permissions, and bit math. Knowing how they relate makes the code make sense.
What each base means
A base is just how many digits a system uses before it rolls over to the next place.
- Binary (base 2): digits 0 and 1. How computers actually store everything.
- Octal (base 8): digits 0 to 7. Shows up in Unix file permissions like
755. - Decimal (base 10): digits 0 to 9. The everyday system.
- Hexadecimal (base 16): digits 0 to 9 then A to F, where A is 10 and F is 15.
Each position is worth a power of the base. In decimal, 255 is (2 x 100) + (5 x 10) + (5 x 1). In binary, 101 is (1 x 4) + (0 x 2) + (1 x 1), which equals 5. The math is the same idea, just a different base.
Why developers love hex
Hex is popular because it lines up perfectly with binary. One hex digit always maps to exactly 4 binary bits, so two hex digits describe one byte (8 bits). That makes hex a compact shorthand for raw bytes.
You see it everywhere:
- Colors like
#FF8800, where each pair is one color channel from 0 to 255. - Memory addresses in debuggers and stack traces.
- Hashes and byte dumps, which would be unreadable in long binary strings.
Writing FF instead of 11111111 is a lot easier on the eyes.
A worked example
Take decimal 255, the largest value a single byte can hold:
- Decimal:
255 - Hex:
FF(which is15 x 16 + 15) - Binary:
11111111(eight 1s, each bit set)
Notice the binary splits into two groups of four: 1111 and 1111. Each group is one hex digit, and 1111 in binary is F in hex. That 4-bit to 1-hex-digit mapping is the whole trick.
Convert instantly
Doing this by hand is good for understanding, but tedious in practice. The Number Base Converter handles it in one step, right in your browser, with nothing sent to a server.
- Open the Number Base Converter.
- Type a value into the base you have, such as decimal
255. - Read the binary, octal, and hex results instantly.
It works in any direction, so you can paste a hex color or a binary string and get the decimal back just as easily.
Related tools
- Unix Timestamp Converter: turn raw epoch numbers into readable dates.
- Hash Generator: produce hex-encoded MD5, SHA-256, and more.
- Color Converter: switch hex colors between RGB and HSL.
Learn the powers of the base once, and let the tool do the arithmetic forever.