Hexadecimal
Binary in a readable shorthand
Hexadecimal is the base-16 number system, using the digits 0 to 9 then A to F. One hex digit encodes exactly four bits, making it a compact, readable shorthand for the bytes and memory addresses a computer works with.
Builds onBinary numbers
From binary numbers you can read any string of bits as a value. The trouble is that the strings get long fast: a byte is eight bits, an address can be sixteen, and
0110 1011 1010 0101 is painful to read, copy, or say aloud. Hexadecimal (base 16, "hex") is the shorthand that fixes this. It is not a new way for the computer to count, just a tidier way for us to write the same bits. Convert between binary, decimal, and hex with the binary converter.Sixteen symbols, one per nibble
Base 16 needs sixteen digit symbols. We borrow
0-9 for the first ten and then the letters A-F for ten through fifteen. The magic is that 16 = 2^4, so one hex digit corresponds to exactly four bits (one nibble). That makes converting a pure lookup, no arithmetic:| binary | decimal | hex |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | 10 | A |
| 1011 | 11 | B |
| 1100 | 12 | C |
| 1101 | 13 | D |
| 1110 | 14 | E |
| 1111 | 15 | F |
1010 is A, 1111 is F. This table is the whole conversion: there is nothing else to memorize.To turn binary into hex, group the bits into nibbles from the right and replace each nibble with its symbol.
1010 0101 becomes A5. To go the other way, expand each hex digit back into its four bits. A byte is always exactly two hex digits, which is why bytes are almost always written in hex.Because plain digits like
10 are ambiguous (is that ten, or the bits one-zero, or hex sixteen?), hex is usually marked. This course writes hex with a 0x prefix, the convention from C and most tools: 0x2A is hex, 42 is decimal, 0010 1010 is binary, and all three are the same number.0x2A = 2*16 + 10 = 42 (decimal) = 0010 1010 (binary)
Try it
Convert the byte
1100 1110 to hex, then to decimal.Answer
Split into nibbles:
1100 and 1110. From the table, 1100 is C and 1110 is E, so the byte is 0xCE. In decimal that is 12*16 + 14 = 206.Why this matters for circuits
Every value you will push around in the processor lessons (a byte on the bus, an instruction, a memory address) is some bits, and you will read them in hex constantly. A program that loads from address
0x0E and adds the byte 0x05 is far easier to follow than one talking about 00001110 and 00000101. Hex is the everyday handwriting of digital systems.Predict, then check
What hex digit does the nibble
1011 spell? Predict it, then set those bits in the figure below and confirm the pattern on the probes.Answer
1011 is 8 + 2 + 1 = 11, which is hex B. In the lab, switch on b3, b1, and b0 (leave b2 off); the probes read 1 0 1 1, the bits behind 0xB.b3-b0 and the pattern they form is a single hex symbol (0-9, then A-F). Open it in the lab, dial in a few nibbles, and name the hex digit each one spells.You can now read and write numbers in binary and hex. Next we move from *numbers* to *logic*: the algebra of
0/1 and the laws (especially De Morgan's) that let you reshape a logic expression, which is exactly what you do when you choose how to build a gate.Frequently asked
What is hexadecimal?
Hexadecimal (hex) is the base-16 number system, using the digits
0-9 then the letters A-F for ten through fifteen. It is a compact, readable shorthand for bits: it does not change how the computer counts, it just lets us write the same bits more tidily.How do you convert binary to hexadecimal?
Group the bits into nibbles (4 bits each) starting from the right, then replace each nibble with its single hex symbol. Because
16 = 2^4, one hex digit is exactly one nibble, so it is a pure lookup with no arithmetic: 1010 0101 becomes A5.Why is hexadecimal used instead of binary?
Hex is used because long binary strings are painful to read, copy, or say aloud, and hex packs four bits into one symbol. A byte is always exactly two hex digits, so values on a bus, an instruction, or a memory address are far easier to follow in hex.
What is the difference between binary and hexadecimal?
Binary is base 2 (digits
0 and 1, one digit per bit) and hexadecimal is base 16 (digits 0-9 and A-F, one digit per four bits). They describe the same value: 0010 1010 in binary, 0x2A in hex, and 42 in decimal are all the same number. Hex is written with a 0x prefix here to avoid ambiguity.Every lesson here builds toward one thing: a working CPU, from the transistor up.
Open the free lab →