You are on page 1of 24

Microprocessors Programming and

Interfacing
ES 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 110 001 101 011 . 111 100 000 110)2 = (26153.7460)8

(10 1100 0110 1011 . 1111 0010 )2 = (2C6B.F2)16


Decimal to Binary
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..
Convert (41)10 to binary Integer Reminder
41
20 1
10 0
5 0
2 1
1 0
Convert (153)10 to Octal 0 1 Ans=101001

153
19 1
2 3
0 2
Ans=(231)8
Decimal to hexadecimal
Convert (227)10 to Integer Reminder
Hexadecimal
227
14 3
0 E

Ans=0xE3H
Decimal fractions to octal

0.513 X 8= 4.104
0.104 X 8= 0.832
0.832 X 8= 6.656

Convert (0.513)10to octal 0.656 X 8= 5.248


0.248 X 8= 1.984
0.984 X 8= 7.872

4 0 6 5 1 7

(0.513)10= (0.406517..)8
Complements

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
9’s complement of 546700 is (999999-546700)=453299
9’s complement of 012398 is (999999-012398)=987601

10’s complement of 012398 is 987602


10’s complement of 246700 is 753300
1’s and 2’s complement
1’s complement of 1011000 is 0100111

1’s complement of 0101101 is 1010010


2’s complement of 1101011 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


+9 00001001 -13 11110011

+22 00100110 -4 11111100

+13 00001101 -9 11110111

-9 11110111 -13 11110011

+4 1 00000100 -22 11101010


Ignore carry
Hexa decimal addition
1 Carry

7A 0111 1010 7 A

3F 0011 1111 3 F

B9 1011 1001 1110 2510


B16 916 B16 916
BCD code
• 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


Other binary codes
Grey code
Binary Gray Code
000 000
001 001
010 011
011 010
100 110
101 111
110 101
111 100

Only one bit changes between successive values


Grey codes

Angular position Measurement where each


segment is assigned a binary number

Load

Drive

Shaft
encoder
Shaft encoder

Shaft Encoder
Alphanumeric Code
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
THANKS

You might also like