Objectives
- To be able to convert positive denary whole numbers (0-255) into 2 digit hexadecimal numbers and visa vera.
- To be able to convert between binary and hexadecimal equivalents of same number.
- Explain the use of hexadecimal numbers to represent binary numbers
Hexadecimal numbers
If you have to work with very large numbers in binary this can become quite confusing. Converting from base 2 to base 10 and back is quite complex and we need something that still uses base 2 but is easier to understand. Since a byte has 8 bits it easily splits into two equal sections, nibbles with 4 bits each. Therefore when working with larger numbers programmers begin to use a number system called Hexadecimal or Hex for short. This is a base 16 number system.
Look at our column headings for a 4-bit number we see that we can represent the range of numbers 0-15.
Look at our column headings for a 4-bit number we see that we can represent the range of numbers 0-15.
If you recall, in base 10 we have the 10 symbols, 0 to 9, if we use the 16 symbols for 0 to 15 we can use a system based on placed values of 16 rather than 2 or 10. We call this hexadecimal or hex for short.
We do, however, need to have symbols for the numbers 10, 11, 12, 13, 14 and 15 because in base 16, 12 would mean 1 lot of 16 and 2 lots of 1 (or 18).
We use the letters A, B, C, D, E and F to represent these values so in hexadecimal we have a set of symbols.
We do, however, need to have symbols for the numbers 10, 11, 12, 13, 14 and 15 because in base 16, 12 would mean 1 lot of 16 and 2 lots of 1 (or 18).
We use the letters A, B, C, D, E and F to represent these values so in hexadecimal we have a set of symbols.
Converting binary to hexadecimal
You can convert binary into hexadecimal fairly easily. Since a byte is made up of 8 bits, it can be easily split into two equal sections. These two sections are known as nibbles and are made up of 4 bits.
Take a binary number:
Take a binary number:
Split it into two nibbles:
The hexadecimal for 00101101 is 2D
Task - in your books
What would the following binary numbers be in hexadecimal?
11101011
10100011
11101011
10100011
Converting hexadecimal to base 10
Converting from hex to base 10 is the same process we have used before with column values, using the values 1 and 16. For example: 23 in base 16 is:
Converting 3C from base 16 to base 10
Converting 5F from base 16 to base 10
Task - in your books
Work out what these hexadecimal numbers represent in denary (that is what we call the number system you use every day).
111
DEF
231
5DE
Can you remember from last lesson how you work it the other way? Work out what these base 10 numbers would be in hexadecimal.
45
235
111
DEF
231
5DE
Can you remember from last lesson how you work it the other way? Work out what these base 10 numbers would be in hexadecimal.
45
235
Where is hexadecimal used?
So where exactly is hexadecimal used?
As we discussed at the beginning of the lesson binary is the language computers actually work in (and we will be looking at that more next lesson), however some programming and scripting languages use hexadecimal to represent colours as trying to use their binary equivalent would be overly complicated.
HTML
CSS
Download the files below and using the instruction sheet change the colour each of the squares using the hexadecimal code given to you. You will need to right click and save, then open the png file in Fireworks.
As we discussed at the beginning of the lesson binary is the language computers actually work in (and we will be looking at that more next lesson), however some programming and scripting languages use hexadecimal to represent colours as trying to use their binary equivalent would be overly complicated.
HTML
CSS
Download the files below and using the instruction sheet change the colour each of the squares using the hexadecimal code given to you. You will need to right click and save, then open the png file in Fireworks.
hex_colours_blank.png | |
File Size: | 146 kb |
File Type: | png |
instructions.docx | |
File Size: | 17 kb |
File Type: | docx |
Task
In your books, write down the questions in the box on the instruction sheet and answer in full.
Then, answer the following questions:
1. Convert the following binary numbers to hexadecimal
a 10010011
b 10101000
c 111011
d 1010101
e 11111111
2. Convert the following hexadecimal numbers to binary and to base 10
a 1A
b 35
c BC
d 4D
1. Convert the following binary numbers to hexadecimal
a 10010011
b 10101000
c 111011
d 1010101
e 11111111
2. Convert the following hexadecimal numbers to binary and to base 10
a 1A
b 35
c BC
d 4D
Extension
What are the names used for units larger than a terabyte?