3F
3F
0011 1111
3 is 0011 and F is 1111.
Type a hexadecimal number and read its binary form, with each digit's four bits shown underneath. It opens on 3F, which is 111111.
Last updated
Coddy teaches you by writing real code in your browser - interactive lessons, instant feedback, and AI help when you get stuck.
Hex and binary line up exactly: one hex digit always stands for four bits, because 16 is 2 to the power 4. So there is no arithmetic to do. Look up each digit's four bits and write them side by side.
The sixteen patterns are all there is to learn. 0 is 0000, 1 is 0001, 8 is 1000, A is 1010 and F is 1111; the table below lists every one.
Leading zeros in the first group can be dropped, since 0011 1111 and 111111 are the same number. Keep them when the value fills a fixed width such as a byte.
F is 1111 and 0 is 0000, so FF is a byte with every bit set.All sixteen hex digits with their 4-bit patterns and decimal values.
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
3F
0011 1111
3 is 0011 and F is 1111.
0xF0
1111 0000
The high four bits are set and the low four are clear, which is how a mask selects half a byte.
#FF8800
11111111 10001000 00000000
Each pair of hex digits becomes one byte of eight bits.
CAFE
1100 1010 1111 1110
C is 1100, A is 1010, F is 1111 and E is 1110.
A5B, the 5 is 0101, not 101.A is one digit with the value 10, and its bits are 1010.bin(int('3F', 16)) returns '0b111111'. To keep all eight bits, use format(int('3F', 16), '08b'), which returns '00111111'.