Microprocessors & Interfacing From base r to base 10 Using - - PowerPoint PPT Presentation

microprocessors interfacing
SMART_READER_LITE
LIVE PREVIEW

Microprocessors & Interfacing From base r to base 10 Using - - PowerPoint PPT Presentation

Number Conversion Microprocessors & Interfacing From base r to base 10 Using (a a ...a a . a ...a ) Number Conversion n n 1 1 0 - 1 - m r n n 1 1 m a r a r ... a r


slide-1
SLIDE 1

S2, 2008 COMP9032 Week1 1

Microprocessors & Interfacing

Number Conversion

Lecturer : Dr. Annie Guo

S2, 2008 COMP9032 Week1 2

Number Conversion

  • From base r to base 10

– Using

  • Examples:

m m 1 1

  • 1

1 n 1 n n n r m

  • 1
  • 1

1 n n

r a ... r a a r a ... r a r a ) ...a a . a ...a a (a

− − − − − − − − − − − − − − − − − − − − − − − −

× × × × + + + + + + + + × × × × + + + + + + + + × × × × + + + + + + + + × × × × + + + + × × × × = = = =

S2, 2008 COMP9032 Week1 3

Examples

  • From base 2
  • From base 16

11.5 2 1 1 2 1 2 2 1 ) (1011.1

  • 1

2 3 2

= = = = × × × × + + + + + + + + × × × × + + + + × × × × + + + + × × × × = = = = 266 10 16 16 1 (10A)

2 16

= = = = + + + + × × × × + + + + × × × × = = = =

S2, 2008 COMP9032 Week1 4

Number Conversion

  • From base 10 to base r

Based on the formula – For whole number

  • Divide the number/quotient repeatedly by r until the quotient is

zero and the remainders are the digits of base r number, in reverse order

– For fraction

  • Multiply the number/fraction repeatedly by r, the whole numbers
  • f the products are the digits of the base r fraction number

m m 1 1

  • 1

1 n 1 n n n r m

  • 1
  • 1

1 n n

r a ... r a a r a ... r a r a ) ...a a . a ...a a (a

− − − − − − − − − − − − − − − − − − − − − − − −

× × × × + + + + + + + + × × × × + + + + + + + + × × × × + + + + + + + + × × × × + + + + × × × × = = = =

slide-2
SLIDE 2

S2, 2008 COMP9032 Week1 5

Examples

  • To base 2

– To convert (11.25)10 to binary

  • For whole number (11)10 – division (by 2)

11 1 5 1 2 1 1

  • For fraction (0.25)10 – multiplication (by 2)

0.25 0.5 0.0 1

(11.25)10=(1011.01) 2

S2, 2008 COMP9032 Week1 6

Examples

  • To base 16

– To convert (99.25)10 to hexadecimal

  • For whole number (99)10 – division (by 16)

99 3 6 6

  • For fraction (0.25)10 – multiplication (by 16)

0.25 0.0 4

(99.25)10=(63.4) hex

S2, 2008 COMP9032 Week1 7

Number Conversion

  • Between binary and octal

– Direct mapping based on the observation: – The expressions in parentheses, being less than 8, are the octal digits.

2 2 1 2 2 1 2 2 2 6 2 3 2 2 3 2 6 2

8 ) (mn0 8 ) (jkl 8 ) (fgh 8 ) (cde 8 ) (0ab 2 0) 2 n 2 (m 2 l) 2 k 2 (j h) 2 g 2 (f 2 e) 2 d 2 (c 2 b) 2 (a jklmn) (abcdefgh.

− − − − − − − − − − − − − − − −

⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ = = = = ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ + + + + ⋅ ⋅ ⋅ ⋅ = = = =

S2, 2008 COMP9032 Week1 8

Number Conversion

  • Between binary and octal (cont.)

– Binary to octal

  • The binary digits (“bits”) are grouped from the radix point, three

digits a group. Each group corresponds to an octal digit.

– Octal to binary

  • Each of octal digits is expanded to three binary digits
slide-3
SLIDE 3

S2, 2008 COMP9032 Week1 9

Examples

  • Binary to octal

– Convert (10101100011010001000.10001) 2 to octal :

010 101 100 011 010 001 000 . 100 010 2 = 2 5 4 3 2 1 0 . 4 2 8 = 2543210.42 8 .

  • Note:

– Whole number parts are grouped from right to left. The leading 0 is optional – Fractional parts are grouped from left to right and padded with 0s

S2, 2008 COMP9032 Week1 10

Examples

  • Octal to binary

– Convert 37425.62 8 to binary :

3 7 4 2 5 . 6 2 8 = 011 111 100 010 101 . 110 010 2 = 11111100010101.11001 2

  • Note:

– For whole number parts, the leading 0s can be omitted. – For fractional parts, the trailing 0s can be omitted.

S2, 2008 COMP9032 Week1 11

Number Conversion

  • Between binary and hexadecimal

– Binary to hexadecimal

  • The binary digits (“bits”) are grouped from the radix point, four

binary digits a group. Each group corresponds to a hexadecimal digit.

– Hexadecimal to binary

  • Each of hexadecimal digits is expanded to four binary digits

S2, 2008 COMP9032 Week1 12

Examples

  • Binary to hexadecimal

– Convert 10101100011010001000.10001 2 to hexadecimal :

1010 1100 0110 1000 1000 . 1000 1000 2 = A C 6 8 8 . 8 8 16 = AC688.8816 .

  • Note:

– Whole number parts are grouped from right to left. The leading 0 is optional – Fractional parts are grouped from left to right and padded with 0s

slide-4
SLIDE 4

S2, 2008 COMP9032 Week1 13

Examples

  • Hexadecimal to binary

– Convert 2F6A.78 16 to binary :

2 F 6 A . 7 8 16 = 0010 1111 0110 1010 . 0111 1000 2 = 10111101101010.01111 2

  • Note:

– For whole number parts, the leading 0s can be omitted. – For fractional parts, the trailing 0s can be omitted.

S2, 2008 COMP9032 Week1 14

Conversion to binary via octal

The direct conversion of 200110 to binary looks like this ...

2001 1000 1 500 250 125 62 1 31 15 1 7 1 3 1 1 1 1

... and gives 11111010001. It may be quicker to convert to octal first ...

2001 250 1 31 2 3 7 3

... yielding 3721 8 , which can be instantly converted to 11 111 010 001 2 .