9
DECIMAL BASE • Based on power of 10 • In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the hundreds, the 2 represent the thousands. • 2, 468 = 8*1 + 6*10 + 4*100 + 2*1000 • You can use ANY number for a base

DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Embed Size (px)

Citation preview

Page 1: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

DECIMAL BASE

• Based on power of 10• In the number 2,468 – from right to left -- the

8 represents the ones, the 6 represents the tens, the 4 represents the hundreds, the 2 represent the thousands.

• 2, 468 = 8*1 + 6*10 + 4*100 + 2*1000• You can use ANY number for a base

Page 2: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Hexadecimal Numbers – Base 16Decimal Number Hexadecimal Number

0 01 12 23 34 45 56 67 78 89 910 A or a11 B or b12 C or c13 D or d14 E or e15 F or f

Page 3: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Hexadecimal Numbers cont.

• 0x283 – C++ uses 0X or 0x to indicate that the number is hexadecimal. ( i. e. if you have the number 283 how would you know if it is a hexadecimal or decimal ? )

Page 4: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Hexadecimal to decimal conversion

• 0X283 = 3 * 16^0 + 8*16^1 + 2*16^2 = = 3*1 + 8*16 + 2*256 = 637

283h = 637d ( another way to differentiate between hexadecimal and decimal but this notation is good in assembly language and for humans too )

Page 5: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Binary Numbers ( base 2 )

• The computer’s number system• Whether you write a n umber in decimal,

hexadecimal, octal, or even other base, the computer stores it in binary.

• 10011011• The memory is commonly organized in units

called bytes ( 1 byte = 8 bits )

Page 6: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Conversion Binary numbers to Decimal

• 100110111 = 1*2^0 + 1 * 2^1 + 1 * 2^2 + 0*2^3 + 1*2^4 + 1*2^5 +

0*2^6 + 0*2^7 + 1*2^8 = 1*1 + 1 * 2 + 1 * 4 + 0 * 8 + 1

* 16 + 1* 32 + 0 * 64 + 0 *128 + 1 * 256= 1 + 2 + 4 + 0 + 16 + 32 + 0 + 0 + 256 = 311

Page 7: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Easier Way to convert binary to base 10

256 128 64 32 16 8 4 2 1

1 0 0 1 1 0 1 1 1

ALGORITHM1. Write the binary number2. Starting left to right write the corresponding powers of 2 which happen to be 1 – 2 – 4 …..3. In other words, each digit to the right carries double the weight of the previous digit4. Discard the rows that the binary number is 0. Add the rest:1 + 2 + 4 + 16 + 32 + 256 = 311

Page 8: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Base TableDecimal Digit Binary Digit Hexadecimal Digit

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

10 1010 A

11 1011 B

12 1100 C

13 1101 D

14 1110 E

15 1111 F

Page 9: DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the

Conversion from Decimal to Binary and Hexadecimal

• LONG DIVISION…..• Pay attention in class • Or Google – there are excellent sites that you

can learn how to do it:• Here is one of them:• http://www.cs.iupui.edu/~n241/readings/binc

onv.html#Dec2Bin1