Upload
ppskc1989
View
108
Download
3
Embed Size (px)
Citation preview
Microprocessors Programming and InterfacingES C 263
Number systems
Structure• Number systems• Decimal• Binary• Hexa Decimal• Operations• BCD Codes
Number Systems
Decimal (0,1,2,3,4,5,6,7,8,9) Octal (0,1,2,3,4,5,6,7) Hexadecimal (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) Binary (0,1)“A number anan-1a2a1a0a-1a-m expressed in base-r system,
has coefficients multiplied by powers of r “
an.rn+an-1.rn-1+………….+a2.r2+a1.r1+a0.r0+a-1.r-1+a-
2.r-2+……a-m.r-m
Convert to decimal
(B65F)16 = 11 X 163 + 6 X 162 + 5 X 161 +15 = (46687)10
(4021.2)5=4 X 53 + 0 X 52 + 2 X 51 + 1 X 50 + 2 X 51 = (511.4)10
(1010.011)2 = 23 + 21 + 2-2 + 2-3 = (10.375)10
Binary <-> Octal and Hexadecimal
(10 1100 0110 1011 . 1111 0010 )2 = (2C6B.F2)16
(10 110 001 101 011 . 111 100 000 110)2 = (26153.7460)8
Repeated division steps: Divide the decimal number by 2 Write the remainder after each
division until a quotient of zero is obtained.
The first remainder is the LSB and the last is the MSB
Decimal to Binary
Decimal to binary..
10
Convert (153)10 to Octal
0
5 0
41
20 1
1 0
2 1
Ans=101001
Integer ReminderConvert (41)10 to binary
2 3
0 2
15319 1
Ans=(231)8
0 1
Decimal to hexadecimal
0 E
227
14 3
Ans=0xE3H
Integer ReminderConvert (227)10 to Hexadecimal
Decimal fractions to octal
0.513 X 8= 4.104
0.104 X 8= 0.832
0.832 X 8= 6.656
0.656 X 8= 5.248
0.248 X 8= 1.984
0.984 X 8= 7.872
(0.513)10= (0.406517..)8
Convert (0.513)10to octal
4 0 6 5 1 7
Two types namely radix and diminished radix complement• Diminished Radix or (r-1)’s complement : For a number N
with n digits, it is defined as (rn-1)-N• Radix or r’s complement : For a number N with n digits, it is
defined as (rn-1)-N+1
Complements
9’s complement of 546700 is (999999-546700)=4532999’s complement of 012398 is (999999-012398)=987601
10’s complement of 012398 is 98760210’s complement of 246700 is 753300
1’s and 2’s complement
1’s complement of 1011000 is
2’s complement of 1101011 is
0100111
10100101’s complement of 0101101 is
0010101
2’s complement of 0110111 is 1001001
Signed Binary Numbers
Signed magnitude of +7 00000111
Signed magnitude of -7 10000111
Represent +7 in 2’s complement form
Place 0 in sign bit 0
Place magnitude in remaining 7 bits 00000111
Represent -7 in 2’s complement form
Start with 8 bit code for +7 00000111
Invert each bit including the MSB 11111000
Add 1 11111001
Signed binary numbers
Get the magnitude of -7
Its 2’s complement is 11111001
MSB is 1. So magnitude is in 2’s complement.Invert all bits including sign. 00000110
Add 1 00000111
Range of numbers in sign magnitude
Signed binary Decimal
01111111 +127
------
00000001 +1
00000000 Zero
11111111 -1
-------
10000001 -127
10000000 -128
Addition
+13 00001101
+9 00001001
+22 00100110
+13 00001101
-9 11110111
+4 000001001
Ignore carry
+9 00001001
-13 11110011
-4 11111100
-9 11110111
-13 11110011
-22 11101010
Hexa decimal addition
7A 0111
3F
1010
0011 1111
B9 1011 1001
7 A
3 F
1110 2510
B16 916
1 Carry
B16 916
• Each decimal digit is represented using 4 bits.• Ex: convert 87410 to BCD:
8 7 4 0100 0111 0100 = 010001110100BCD
• Reverse the process to convert BCD to decimal
BCD code
Other binary codes
Binary Gray Code000 000001 001010 011011 010100 110101 111110 101111 100
Grey code
Only one bit changes between successive values
Grey codes
Angular position Measurement where each segment is assigned a binary number
Drive
Load
Shaft encoder
Shaft encoder
Shaft Encoder
ASCII – American Standard Code for Information Interchange:
• A binary code for letters, numerals, special characters and control characters.
• Seven bit code: 27 = 128 possible code groups
• 94 Graphic Characters and 34 non printing control characters
Alphanumeric Code
Alphanumeric Code
THANKS