Hexadecimal is base 16. Its digits are 0 to 9 and A to F, where A is 10 and F is 15. One hex digit equals exactly 4 binary bits. That grouping is called a nibble. Each hex digit maps directly to a 4-bit binary value. Two hex digits make one byte. That compact, readable shorthand is why programmers reach for hex when staring at raw binary data, memory addresses, or colour codes. A BCD clock column also groups bits in fours, but it stops at 9. Hex uses the full 16 values, and that is the distinction that matters here.

Why Bits Are Grouped in Fours

Binary numbers get long fast. A single byte spans 8 bits. Writing eight 1s in a row is hard to read and easy to mistype. Split those 8 bits into two groups of four and you have a nibble. Each nibble can hold 16 values. Hexadecimal supplies exactly 16 symbols. One hex digit represents any 4-bit pattern. That direct one-to-one fit is the whole reason programmers group bits in fours: every nibble becomes a single, glanceable hex digit.

Hexadecimal Explained Base 16 in Practice

Base 16 means each digit position represents a power of 16, read from right to left: 16^0, 16^1, 16^2. Digits 0 through 9 stand for values zero through nine. A is 10, B is 11, C is 12, D is 13, E is 14, and F is 15. Take the hex number 0x3B. The 3 sits in the 16s place: 3 times 16 is 48. B sits in the 1s place as 11. 48 plus 11 equals 59. The 0x prefix marks a hex literal in many programming languages.

Binary to Hex the Direct Mapping

Split Into Groups of Four

Start from the rightmost bit. Split the binary number into groups of 4 bits. Add leading zeros to the leftmost group if it is short.

Map Each Nibble to a Hex Digit

Write the hex digit for each 4-bit group using this mapping:

  • 0000=0, 0001=1, 0010=2, 0011=3
  • 0100=4, 0101=5, 0110=6, 0111=7
  • 1000=8, 1001=9, 1010=A, 1011=B
  • 1100=C, 1101=D, 1110=E, 1111=F

Combine the hex digits in order. For example, the binary number 11111111 splits into 1111 1111. 1111 is F, so the result is 0xFF. A longer binary number splits into two nibbles, and mapping each gives the hex result 0x3B, which equals 59.

Hex Digits 0-F and the Nibble

Hex digits 0 through F cover every possible 4-bit pattern. A nibble holds 16 values, from 0000 to 1111. Hex digits represent those 16 values directly. Take 0x17. In binary that is 0001 0111, which equals 23. Two hex digits make one byte. 0xFF is 11111111 in binary. That is the maximum value a byte can hold. This direct mapping is why hex became the standard shorthand for binary in computing.

How Hex Differs from BCD

Binary Coded Decimal also uses 4 bits per digit, but only for the values 0 to 9. BCD stops at binary 1001. It never uses the patterns 1010 through 1111, the values A through F. A BCD clock column uses 4 bits to show a decimal digit. Hex uses the same 4 bits to show any of 16 values. Both use nibbles. Hex is base 16. BCD is base 10 encoded in binary. This distinction matters whenever you see a clock that lights up four dots per column: if a column ever shows more than 9, you are looking at hex, not BCD.

Practical Conversions Between Hex and Binary

Work these examples to lock in the mapping. Each one uses the nibble table from the previous section.

  • 0x3B to binary: 3 is 0011, B is 1011. Result: 0011 1011.
  • 0x17 to binary: 1 is 0001, 7 is 0111. Result: 0001 0111.
  • 0xFF to binary: F is 1111. Result: 1111 1111.
  • A binary number to hex: Split into two nibbles. The first nibble maps to 3, the second to B. Result: 0x3B.
  • Another binary number to hex: Split into two nibbles. The first nibble maps to 1, the second to 7. Result: 0x17.

Using Hex in Programming

Write hex numbers with the 0x prefix. The compiler or interpreter reads the digits that follow as base 16. 0xFF is 255. 0x3B is 59. 0x17 is 23. Reach for hex when you work with memory addresses, colour codes, bitmasks, or raw binary data. It is more compact than binary and, when bits matter, far clearer than decimal.