hexadecimal & decimal conversions

11
Hexadecimal & Decimal Conversions Hexadecimal to Decimal & Back Again Mr. Akuna 2009

Upload: chassidy-evans

Post on 31-Dec-2015

61 views

Category:

Documents


7 download

DESCRIPTION

Hexadecimal & Decimal Conversions. Hexadecimal to Decimal & Back Again Mr. Akuna 2009. Introduction to Hexadecimal Numbers. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Hexadecimal & Decimal Conversions

Hexadecimal & Decimal Conversions

Hexadecimal to Decimal & Back Again

Mr. Akuna 2009

Page 2: Hexadecimal & Decimal Conversions

Introduction to Hexadecimal Numbers• Hexadecimal numbers (sometimes called hex for short,

when used in the context of computers) are taken from the words hex, meaning six, and decimal, meaning ten, so combining the two you get 16 (6 + 10).

• Hexadecimal numbers are numbers just like decimal numbers but are in base 16 instead of base 10. The base tells you how many digits can be used.

In base 10 (decimal) there are 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

In base 16 (hexadecimal) there are 16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Page 3: Hexadecimal & Decimal Conversions

Introduction to Hexadecimal Numbers• Now that we know what digits are involved let’s compare them to

their decimal equivalents To repeat in base 16 (hexadecimal) there are 16 digits:

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

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

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Hexadecimal

Decimal Equivalent

• Notice from the table that after we reach 9 the next number in decimal requires two digits while for hexadecimal you only need 1 character. This becomes important when you want to show large numbers. We will get back to this, but first let’s take another look at decimal numbers.

Page 4: Hexadecimal & Decimal Conversions

104 103 102 101 100

10000 1000 100 10 11 2 7 4

To better understand hexadecimal let’s take a closer look at decimal numbers. For example, the number 1274. You understand the number, but let’s break down the digit in each position.

Next take the value for each position. Add 1000*1 + 100*2 + 10*7 + 1*4 = 1274 notice 10000 is not added in since its position is implied as a leading 0, and all leading zeros are ignored. Probably all this is obvious to you since you work with decimal numbers all the time.

A Closer Look at Decimal

Page 5: Hexadecimal & Decimal Conversions

163 162 161 160

4096 256 16 11 A F 9

10 15

Let’s apply what we just did in decimal to hexadecimal. For example, the hexadecimal number 1AF9. Just like we did in decimal let’s break down the digit in each position.

Next take the value for each position. Add 4096*1 + 256*10 + 16*15 + 1*9 = 6905 (decimal) notice an extra step was used to convert the characters A and F to their decimal equivalents but the process was the same as before just like the decimal number 1274.

Hexadecimal to Decimal Conversion

Page 6: Hexadecimal & Decimal Conversions

Okay so we can take a hexadecimal number 1AF9 and convert it to its decimal equivalent, 6905. How about the number 1023. Just saying the number 1023 doesn’t make it clear whether this is a hexadecimal number 1023 or a decimal 1023 and we know these two numbers are not the same.

To avoid such problems we notate hexadecimal numbers in several possible ways as shown in the following:

• 0x1023 the 0x being the notation for hexadecimal• 1023h the h being the notation for hexadecimal• Hex 1023

Hexadecimal numbers are used to give color information in HTML code, such as #FF80CC, where the # is the notation for hexadecimal. Also important is the hexadecimal number is NOT interpreted as a single number, but rather three sets of 2 hexadecimal digits, each representing one of three colors, RGB.

Hexadecimal Notation

Page 7: Hexadecimal & Decimal Conversions

RGB, Red, Green and Blue, is used in HTML to provide a specific color designation, to give the hexadecimal color it would be #RRGGBB.

Each color is represented by two hexadecimal characters,• # being the notation for hexadecimal• RR being red with a value range of 00 to FF (0 to 255 decimal)• GG being green with a value range of 00 to FF (0 to 255 decimal)• BB being blue with a value range of 00 to FF (0 to 255 decimal)

To convert this type of hexadecimal number you first split the hexadecimal number into 3 sets of 2. For example #FF80CC:

RGB Provided in Hexadecimal

161 160

16 1F F

161 160

16 18 0

161 160

16 1C C

16*15+1*15=255 16*8+1*0=128 16*12+1*12=204

#FF80CC = RGB(255, 128, 204)

Page 8: Hexadecimal & Decimal Conversions

163 162 161 160

4096 256 16 12 D 4 5A 1 0 E

F F

0 0

8 0

Check for Understanding• What is the value of 0x2D45 ?• What is the value of A10Eh ?• What is the value of #FF0080 ?

11589

41230

RGB (255, 0, 128)

Page 9: Hexadecimal & Decimal Conversions

Decimal to Hexadecimal ConversionTake the decimal number 8877, look at each number

starting with 4096, how many times can 8877 be divided by 4096, the answer is 2. (4096*2) = 8182, subtract that number from 8877, the remainder is 695. How many times can 695 be divided by 256, the answer is 2. Subtract (256*2)=512 from 695, the remainder is 183. How many times can 183 be divided by 16, the answer is 11 (B in hexadecimal). Take 183 and subtract 176=(16*11), the remainder is 7. How many times can 7 be divided by 1, the answer is 7, the remainder is 0. Put the numbers together and you have the hexadecimal number 22B7 or 0x22B7

8877

-8182

695

-512

183

-176

7

-7

0

163 162 161 160

4096 256 16 12 2 B 7

Page 10: Hexadecimal & Decimal Conversions

Check for Understanding• What is decimal 15309 in hexadecimal?• What is decimal 9156 in hexadecimal?• What is decimal 255 in hexadecimal?

15309

9156

255

163 162 161 160

4096 256 16 1

3 B C D

2 3 C 4

F F

3BCD

23C4

FF

Decimal Hexadecimal

Page 11: Hexadecimal & Decimal Conversions

Final Check for Understanding

• Click on this link to bring up the Hexadecimal-Decimal Worksheet.

• Print & complete the worksheet

• Turn in this worksheet with your other assignments.