HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert...

20
HEXADECIMAL NUMBERS

Transcript of HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert...

Page 1: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

HEXADECIMAL NUMBERS

Page 2: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

OBJECTIVES

• Be able to explain what a hexadecimal number is

• Be able to convert up to denary 255 to hexadecimal and vice versa

• Understand and be able to explain why we use hexadecimal

Page 3: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

Binary Numbers

binary denary

hexa-decimal

binary denary hexa-decimal

0000 0 1000 8

0001 1 1001 9

0010 2 1010 10

0011 3 1011 11

0100 4 1100 12

0101 5 1101 13

0110 6 1110 14

0111 7 1111 15

Here are the first 16 binary numbers (using 4 bits), and their decimal equivalents. Copy this chart.

Page 4: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Activity

• Complete the chart by writing the first 16 hexadecimal numbers (beginning with 0)

• How many bits do you need to represent the first 16 hexadecimal numbers?

binary denary

hexa-decimal

binary denary hexa-decimal

0000 0 0 1000 8 8

0001 1 1 1001 9 9

0010 2 2 1010 10 A

0011 3 3 1011 11 B

0100 4 4 1100 12 C

0101 5 5 1101 13 D

0110 6 6 1110 14 E

0111 7 7 1111 15 F

Page 5: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Converting hex to denary and back again (up to denary 255)

• We naturally understand denary numbers• We know that 1089 =

(1x1000)+(0x100)+(8x10)+(9x1)• For hexadecimal it is the same but for base 16For example: A9

(10x16)+(9x1) = 160 + 9 = 169

10 9

Page 6: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Convert these hexadecimal numbers to denary – show working

• FF• AC• 8D• 99• EE• 42• EXTRA CHALLENGE – TRY THESE :• FFFF, EEF4, CBCB, 0101, DDFF

Page 7: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Convert these hexadecimal numbers to denary – ANSWERS

• FF = (15 X 16) + (15 X 1) = 240 + 15 = 255• AC = (10 X 16) + (12 X 1) = 160 + 12 = 172• 8D = (8 X 16) + (13 X 1) = 128 + 13 = 141• 99 = (9 X 16) + (9 X 1) = 144 + 9 = 153• EE = (14 X 16) + (14 X 1) = 224 + 14 = 238• 42 = (4 X 16) + (2 X 1) = 64 + 2 = 66

Page 8: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

THE GOOD NEWS

• For the purposes of GCSE you need to be able to convert denary 255 to hexadecimal and back again (2 hexadecimal digits)

Page 9: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

DENARY TO HEXADECIMAL

• How would you convert 200 denary to hexadecimal?

1. Divide 200 by 16 = 2. 12 (lots of 16) remainder 8 (units)3. 12 as a hex = C and 8 is 84. Answer is C8

Page 10: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Convert these denary to hexadecimal

• 32• 255• 59• 159• 230

Page 11: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

Binary and Hexadecimal

0000 = 0 1000 = 8

0001 = 1 1001 = 9

0010 = 2 1010 = A

0011 = 3 1011 = B

0100 = 4 1100 = C

0101 = 5 1101 = D

0110 = 6 1110 = E

0111 = 7 1111 = F

Hexadecimal works by grouping binary bits into groups of 4 (starting from the right). Each group (a nibble) is assigned a hex digit value. The digits are the same as for decimal up to 9, and then letters A through F are used for 10 through 15.

Thus the 8-bit binary number

1011 0010

converted to hex is

B2

Page 12: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

What would these binary numbers be as hexadecimal?

• 11111111• 00000000• 10101010• 01011111• 11110000Extension – write the proof by converting each to denary

Page 13: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Which of these is easier to remember?

• 01011011 01011011 or 5B5B• Humans are not good at remembering long

strings of numbers and binary numbers are often long and unwieldy

Page 14: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

Why hexadecimal?

• Hex numbers are shorter/more memorable than equivalent binary numbers..

• ... and can easily be converted to and from binary...

• ... as each hexadecimal digit corresponds to 4 binary digits

Page 15: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

USES OF HEXADECIMAL•Used in error messages•Representation of colours in images and HTML •Challenge! – what other uses of hexadecimal in computing can you find?

Page 16: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

The RGB Color System

• RGB values are based on the Red, Green, Blue primary color system.

• Each of the three primary colors is assigned a numerical strength.

• The three strengths of Red, Green, and Blue define the color.

Page 17: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

Expressing Colors in Hex• Strengths of the primary colors are defined using 8-

bit numbers (bytes). An 8-bit number can be represented using two hex digits.

• The value of the hex number ranges from 00 to FF, corresponding to a range from 0 to 255 decimal.

• A strength of 00 means the color is completely absent. A strength of FF or 255 means the color is at its maximum.

• An RGB color is thus represented by three 8-bit numbers (bytes), or six hex digits.

Page 18: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

© 2004, Robert K. Moniot

Expressing Colors in Hex• Note that 40 is ¼ of full strength, 80 is ½, C0 is ¾.• Here are some examples of colors expressed in hex:

"#000000" Black (all colors off) (what do you think white is?)

"#FFFFFF" White (all colors max)"#FF0000" Red (red max, green & blue off)"#00FF00" Green"#0000FF" Blue"#FFFF00" Yellow (equal amounts of red & green)"#AEEEEE" Turquoise"#808080" Gray (all colors half max)

Page 19: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

ACTIVITY• Open notepad• Type in:<body bgcolor=#ff0000></body>• Save the file with the extension .htm. Make sure

not to save as a .txt file. • Double-click on the file to open with your

default browser. Now repeat the process with different colour codes.

Page 20: HEXADECIMAL NUMBERS. OBJECTIVES Be able to explain what a hexadecimal number is Be able to convert up to denary 255 to hexadecimal and vice versa Understand.

HEXADECIMAL BINGO

• Highlight the decimal equivalent of the hexadecimal number given