dh2t 34 – hnc computer architecture 1 week 2 introduction to the hexadecimal number system © c...

21
DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System /Aberdeen College 2004 © C Nyssen /Aberdeen College unless otherwise stated omphe, compass, chess, caterpillar, binary printer all © romtech, with non-distribution licence sh © Mark Pelissier, with permission an © clipart.com, with non distribution licence Mark 1© Manchester University, with permission /9/04

Upload: monica-amason

Post on 14-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

DH2T 34 – HNC Computer Architecture 1

Week 2Introduction to the Hexadecimal

Number System

© C Nyssen/Aberdeen College 2004All images © C Nyssen /Aberdeen College unless otherwise statedArc de Triomphe, compass, chess, caterpillar, binary printer all © romtech, with non-distribution licenceConvict fish © Mark Pelissier, with permissionConfused man © clipart.com, with non distribution licenceLady with Mark 1© Manchester University, with permissionPrepared 7/9/04

Page 2: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

The number 16 is not a “natural” counting base for 10-fingered humans.

However it appears a lot in human society – because of the unique properties of the number 16.

It is an exact square - 42, or 24.

Page 3: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

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.

Page 4: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Bookbinders use a standard format of sixteenmo – the paper is divided into sixteen leaves.

Pre-decimal Imperial weights and measures used 16oz to a pound.

Caterpillars usually have 16 legs! (But only 6 when they become butterflies).

Page 5: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

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….

Page 6: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

… because the human eye becomes very confused when dealing with large groups of similar looking objects!

Page 7: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

A method had to be found to “convert” large binary numbers to something that humans find easier to read and manipulate.

As base 2 does not convert to base 10 very easily, we use base 16 – hexadecimal – instead.

Page 8: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

You can buy special base-converting calculators to convert values between binary, decimal, hexadecimal and octal (a base of 8).

Or a useful website is -http://www.calculator.org/CalcHelpCD/basen.html

Page 9: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Each hexadecimal column uses a power of 16.

65536 4096 256 16 1

164 163 162 161 160

But we only have 10 digits – numbered 0 to 9 – so to make up 16 symbols, we use the letters A – F as well.

0 1 2 3 4 5 6 7 8 9 A B C D E F

Page 10: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Some examples of computers displaying information in a hexadecimal format….

h2.arch, h3.arch{ align = "center"; background-color: ffcccc;}h1.java{ font-size: 110%; font-family: trebuchet; background-color: 99ff66;}

Page 11: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Converting binary to hex is easy – exploiting the relationship between the numbers 4 and 16.

Begin by dividing the binary number into “nibbles” – groups of 4 – working from right to left.

1 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0

Page 12: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Each nibble can only hold a value of between 0 and 15.

Replace each nibble with the equivalent hexadecimal digit….

…and 16 binary digits have been replaced with 4 hexadecimal ones!

1 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0

9 14 or E 3 10 or A

Page 13: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

It works the other way round, too….

…expand each hexadecimal digit to four binary ones….

…and your 8-digit hexadecimal number has become a 32-bit binary one!

E 7 F 4 C 0 1 D

1110 0111 1111 0100 1010 0000 0001 1011

Page 14: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Sometimes you will have to convert directly from decimal to hex….

…we use the long division process that we looked at last week with the binary conversion.

Page 15: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

To convert a decimal number – 7896532 - to

hexadecimal …

…start by dividing by 16 …

…and continue until you run out of numbers.

(When dividing, just do the whole numbers,

ignore the remainders for the moment…)

Page 16: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

Now we turn our attention to the remainders – multiply them all by 16 to get the red column on the right…..…read from the BOTTOM UP to get 787DD4h …

…or 0111 1000 0111 1101 1101 0100 in binary!

Page 17: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

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

163 162 161 160

4096’s 256’s 16’s 1’s

5 F 7 B

5 x 4096 = 20480

F or 15 x 256 = 38407 x 16 = 112

B or 11 x 1 = 11

20480 + 3840 + 112 + 11 = 24443

Page 18: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

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

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

DAF3h 1101 1010 1111 00112 5605110

…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 “hexidecimal base”.

1101 1110 1111 00002 DEFOh5707210

Page 19: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

It is important to remember that computers do not actually store things in hexadecimal. Everything is stored in binary!

Computers just display things in hexadecimal to make life easier for the human audience.

1101 1111 0000 0100

Page 20: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

One for you to try…..

FACE16 in binary? 1111 1010 1100 1110

0101 0000 1101 0000 1111 11112 in hex?

5 0 D 0 F F

Page 21: DH2T 34 – HNC Computer Architecture 1 Week 2 Introduction to the Hexadecimal Number System © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen

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.