How to Convert Hex to Binary and Binary to Hexadecimal
The Hexadecimal Numbering System
The base 16, hexadecimal (abbreviated to hex) numbering system is regularly used in computer coding for conveniently representing a byte or word of data. This guide shows you how to convert from hex to binary and binary to hexadecimal.
Decimal, the Base 10 Numbering System
Before we learn how to convert hex to binary, let's try and understand how the base 10 system works.
The decimal, denary or base 10 numbering system that we use in everyday life makes use of ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
So to count you start with 0, then continue 1...2...3...4...5...6...7...8...9
What happens when you get to ten? There's no symbol for ten, so it's represented as
10
Which means 1 ten and no units
Similarly when you get to 99, there's no symbol for one hundred, so you write one hundred as 100.
So writing a number in the base 10 system involves using symbols in a "units", "tens", "hundreds", "thousands" place and so on
So 145 really means "one hundred, 4 tens and 5 units" although we just think of it as one hundred and forty five.
Hexadecimal, the Base 16 Numbering System
Hexadecimal or "hex" is a numbering system which uses 16 symbols. We saw that decimal used 10 symbols from 0 to 9. Hex expands on this by adding 6 more, the capital letters A, B, C, D, E and F.
So to count from 0 to 15 you go 0...1...2...3...4...5...6...7...8...9
But what happens next?
Simply continue with A...B...C...D...E...F which represents 10, 11, 12, 13, 14 and 15 decimal.
In the decimal system, we saw that when we got to 9, there was no symbol for ten so it was represented as 10 or "one ten and no units".
In the hex system when we get to F which is 15 decimal, we have to represent the next number sixteen as 10 or "one 16 and no units".
Hex to Decimal Table
Hex
 Decimal


0
 0

1
 1

2
 2

3
 3

4
 4

5
 5

6
 6

7
 7

8
 8

9
 9

A
 10

B
 11

C
 12

D
 13

E
 14

F
 15

10
 16

11
 17

12
 18

13
 19

14
 20

15
 21

16
 22

17
 23

18
 24

19
 25

1A
 26

1B
 27

1C
 28

1D
 29

1E
 30

1F
 31

20
 32

21
 33

22
 34

Binary, the Base 2 Numbering System
The binary system used by computers is based on 2 symbols; 0 and 1. So you count 0, 1, there is no symbol for 2, so 2 is represented by 10 or "one 2 and no units". In the same way that there is a units, tens, hundreds, thousands place in the decimal system, in the binary system there is a units, twos, fours, eights, sixteens place etc. in the binary system.
Binary, Decimal and Hex Equivalents
Binary
 Decimal
 Hex


0
 0
 0

1
 1
 1

10
 2
 2

11
 3
 3

100
 4
 4

101
 5
 5

110
 6
 6

111
 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

10000
 16
 10

10001
 17
 11

Indicating the Base of a Number
If a number isn't decimal (base 10), the base can be explicitly indicated by a subscript to avoid confusion. Sometimes the subscript is omitted to avoid excessive detail if the base has been specified earlier in a discussion or if numbers are listed in a table (e.g. numbers may be indicated as hex in the title of the table).
So for instance 1F hex (31 decimal) can be written 1F_{16}
Steps to Convert Hex to Binary
Hex is very easy to convert to binary.
 Write down the hex number and represent each hex digit by its binary equivalent number from the table above
 Use 4 digits and add insignificant leading zeros if the binary number has less than 4 digits. E.g. Write 10_{2 }(2 decimal) as 0010_{2}
 Then concatenate or string all the digits together.
 Discard any leading zeros at the left of the binary number
Steps to Convert Binary to Hex
Binary is also easy to convert to hex.
 Start from the least significant bit (LSB) at the right of the binary number and divide it up into groups of 4 digits. (4 digital bits is called a "nibble")
 Convert each group of 4 binary digits to its equivalent hex value (see table above)
 Concatenate the results together, giving the total hex number
What is Hex Used For?
Because of the ease of converting from hex to binary and vice versa, it's a convenient shorthand for representing byte values i.e. numbers from 0 to 255. Also it's compact requiring only 2 digits for a byte and 4 digits for a word.
 Hex dumps are used to display the values of bytes in files. Each byte value is displayed as hex
 Assembly language is written as a series of mnemonic processor instructions. The operand is commonly specified as a hex value. It's also used to indicate the storage location of data
Example of assembly language instruction
Mov is the opcode and 61 hex is the operand
MOV AL, 61h ; Load AL with 97 decimal (61 hex)
Questions & Answers
© 2018 Eugene Brennan