0% found this document useful (0 votes)
67 views25 pages

Computer Systems Fundamentals H175 34: Numbers in Base 16

Uploaded by

dvfgdfggdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views25 pages

Computer Systems Fundamentals H175 34: Numbers in Base 16

Uploaded by

dvfgdfggdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Computer Systems Fundamentals

H175 34

Lecture 2
Numbers in base 16
Why Base 16?
Last week, we saw that a base of 10 is
a natural counting mechanism for
humans.

But a base of 16 appears a lot in


human society too.
This is because of the unique
properties of the number 16.

It is an exact square - 42, or 24.


The Uniqueness of 16…
•The first four odd numbers added – 1+3+5+7
equals 16.
•A compass rose is divided into 16 points.
•Chessboards have 16 black and 16 white pieces.
•They are divided into four quadrants of 16
squares each.
The Uniqueness of 16…
• Bookbinders use a standard format of
sixteenmo, where the paper is divided into
sixteen leaves.
• Caterpillars usually have 16 legs! (But only 6
when they become butterflies).
• Pre-decimal Imperial weights
and measures used
16 ounces to a pound.
Programming In 16
We saw last week that
computers can only store and
manipulate data in a binary
base – base 2.

The earliest computer programs


were written in binary by highly
trained mathematicians. They
were, however, highly prone to
errors….
… because the human eye becomes very confused when dealing with large groups of similar
looking objects!
Converting 2s to…..
A method had to be As base 2 does not
found to “convert” convert to base 10 very
easily, we use base 16 –
large binary numbers hexadecimal – instead.
to something that
humans find easier
to read and
manipulate.
Each Hexadecimal column uses a power of 16.

Column Number 5 4 3 2 1

Power 164 163 162 161 160


Value 65536 4096 256 16 1

But we only have 10 unique symbols using the


digits 0 to 9.

So to make up 16 symbols, we use the letters A –


F as well.
A hexadecimal number will look like this….

Column Number 5 4 3 2 1

Power 164 163 162 161 160


Value 65536 4096 256 16 1
Hex Number 1 8 A 0 9

The above number is worth 100873 in a decimal


base.
We get this by multiplying and adding…..
(1x65536) + (8x4096) + (10x256) + (0x16) + 9
Some examples of
hexadecimal
numbers….
You will be required to convert numbers in a binary
base (base 2) to hexadecimal (base 16). The
question will tell you how many bits of storage to
use.

Example – convert this number to hexadecimal using


16 bit storage.

1 100 001 1 1 111 110 0 0 000 101 0 1 100 110 0

Always begin by dividing the binary number into


“nibbles” (groups of 4) working from right to left.
Each nibble can only hold a value of between 0 and 15.
Replace each nibble with the equivalent hexadecimal
digit….

1001 1110 0011 1010


9 14 or E 3 10 or A

…and 16 binary digits have been


replaced with 4 hexadecimal ones!
It works the other way round…
…expand each hexadecimal digit to four binary
ones….

E 7 F 4 C 0 1 B
1110 0111 1111 0100 1100 0000 0001 1011

…and your 8-digit hexadecimal


number has become a 32-bit
binary one!
Decimal to Hex
Sometimes you will
have to convert
directly from decimal
to hex….
…we can use the
“Columns” process
that we looked at last
week with the binary
conversion.
The Number 17862 converted…
Column Number 5 4 3 2 1

Power 164 163 162 161 160


Value 65536 4096 256 16 1
Hex Number 0 4 5 C 6

We have 0 “lots of 65536….


4 “lots” of 4096 are 16384, leaving 1478 still to allocate
5 “lots” of 256 are 1280, leaving 198 to go
12 “lots” of 16 are 192, leaving 6

Remember you can have up to 15 in each column!


To convert from hex to decimal, we use the “hexadecimal columns” method to
multiply and add.

Column Number 4 3 2 1

Power 163 162 161 160


Value 4096 256 16 1
Hex Number 5 F 7 B

5 x 4096 = 20480
F or 15 x 256 = 3840
7 x 16 = 112
B or 11 x 1 = 11

20480 + 3840 + 112 + 11 = 24443


You can convert from hex – binary – decimal if you prefer….

DAF3h 1101 1010 1111 00112 5605110

….and back again from decimal – binary – hex….

5707210 1101 1110 1111 00002 DEFOh

…because they all mean exactly the same value, it’s just
expressed in different ways.

Note that sometimes a lowercase ‘h’ is used to mean


“hexadecimal base”.
Convert the following….
• F016 to binary • 1111 00002
• 27116 to binary • 0010 0111 00012
• 295A16 to binary • 0010 1001 0101 10102

• 1011 to hex • B16


• 1101 0111 to hex
• D716
• 1010 1100 to hex
• AC16
It is important to remember that computers do not actually
store things in hexadecimal. Everything is stored in binary!

1101 1111 0000 0100

Computers just display things in hexadecimal to make life


easier for the human audience.
If you forget the column headings when
working in 16s, they are easy to work out.
Start with the binary columns....
216 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

...and divide them into nibbles of 4


(remember to always work from right to
left!)
216 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
...and you should see how the base-16
columns line up with the base-2 ones!
216 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20

65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

65536 4096 256 16 1

164 163 162 161 160


Some more for you to try…..

FACE16 in binary?
1111 1010 1100 1110
And Decimal?
64206

0101 0000 1101 0000 1111 11112 in hex?


5 0 D 0 F F
Any Questions?
Summary

Although computers store and manipulate values in


binary, they usually display them in hexadecimal format.
Each group of four bits corresponds to one

hexadecimal digit.
Hexadecimal digits run from 0 -9 then A – F.

The value of each hexadecimal digit rises by a power

of 16 as the columns move to the left.


Hexadecimal values are usually followed by a

lowercase “h”, or a small 16.


Credits
• Manchester MkII © University of Manchester
• Convict Fish © Marc Palissier 2002
• Hex examples © Chrissie Nyssen
• All other graphics © Focus Multimedia with open
licence, unless stated
• All other contents © Aberdeen College 2010-12

You might also like