Hexadecimal numbers: Base sixteen

Hexadecimal is a short way to write binary values. Z80 assembly uses it for bytes and addresses.

Number basics

Sixteen digits

Hexadecimal uses 0–9 and A–F. The letters mean 10–15. Each place is a power of 16. In Z80 code, an h after a number marks it as hexadecimal.

2Ah = 2 × 16 + 10 = 42

Choose a byte

Decimal value

Two hex digits make one byte

A nibble is four bits. One hex digit represents one nibble. The first digit is the high nibble. The second is the low nibble.

Place values in a 16-bit number

Hex place16³16²16¹16⁰
Digit in 1234h1234
Place value4096256161
Contribution4096512484

Add the contributions: 4096 + 512 + 48 + 4 = 4660. So 1234h is 4660 in decimal.

Useful byte examples

HexCalculationDecimalBinary
10h1 × 16 + 0160001 0000
2Ah2 × 16 + 10420010 1010
FFh15 × 16 + 152551111 1111

Numbers 1 to 16 in binary and hexadecimal

The binary column uses a full byte. The hexadecimal column uses two digits for the same 8-bit value.

Decimal8-bit binaryHexadecimal
10000 000101h
20000 001002h
30000 001103h
40000 010004h
50000 010105h
60000 011006h
70000 011107h
80000 100008h
90000 100109h
100000 10100Ah
110000 10110Bh
120000 11000Ch
130000 11010Dh
140000 11100Eh
150000 11110Fh
160001 000010h

The byte examples on this page are unsigned. See Negative numbers and two’s complement to learn how fixed-width values can also represent signed numbers.