Boneyard Tools

Binary and hex number systems explained

How base-two and base-sixteen work, why one hex digit equals four bits, and how to read the two systems side by side.

Binary: counting in base two

Binary represents every value with just two symbols, 0 and 1, each called a bit. Positions from right to left carry the weights 1, 2, 4, 8, 16 and so on, doubling each step, which mirrors how the digits of a decimal number carry powers of ten. To read a binary number you add the weights of the positions that hold a 1, so 1010 is 8 plus 2, which equals 10. Computers use binary because a bit maps cleanly onto a switch that is either off or on.

Hex: base sixteen in four characters

Hexadecimal uses sixteen symbols: the digits 0 through 9 followed by the letters a through f, where a is 10 and f is 15. Each position carries a power of sixteen, so the two-digit value ff is 15 times 16 plus 15, which equals 255. Because sixteen is two to the fourth power, hex lines up perfectly with binary and gives a compact way to write long strings of bits without losing any precision.

Why one hex digit equals four bits

Four bits can represent sixteen distinct patterns, from 0000 to 1111, and hexadecimal has exactly sixteen digits, so the mapping is one to one. This four-bit unit is called a nibble, and two nibbles make one eight-bit byte. That is why a byte is always written as two hex characters: 00 is all zeros, ff is all ones, and a5 is the nibbles 1010 and 0101 side by side.

Reading binary and hex together

To convert by hand, split the binary number into groups of four bits starting from the right, padding the leftmost group with zeros if needed, then translate each group into its hex digit. For example 1111 1111 1010 0101 becomes f, f, a, 5, or ffa5. Going the other way, expand each hex digit back into its four-bit pattern. This tool does the grouping and translation for you and keeps the value exact even for very long inputs.

Frequently asked questions

Why does hex use letters?

Base sixteen needs sixteen single-character symbols, but the decimal digits only supply ten. The letters a through f fill in the values 10 through 15 so each hex position still fits in one character.

What is the 0x prefix I sometimes see?

In many programming languages 0x marks a number as hexadecimal, as in 0xff. It is a language convention, not part of the value, and this converter expects plain binary input without any prefix.

How many hex digits does a byte need?

Exactly two. A byte is eight bits, which is two nibbles of four bits, and each nibble is one hex digit, so byte values run from 00 to ff.