You are on page 1of 32

Microprocessors & Interfacing XX F241 Number systems

KCS Murti

Structure
Number systems Decimal Binary Hexa Decimal Operations BCD Codes

XX F241 Microprocessors KCS Murti

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+a .r-m .r 2 -m

XX F241 Microprocessors KCS Murti

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

XX F241 Microprocessors KCS Murti

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

XX F241 Microprocessors KCS Murti

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

XX F241 Microprocessors KCS Murti

Decimal to binary..
Convert (41)10 to binary Integer 41 20 10 5 2 1 Convert (153)10 to Octal 0 153 19 2 0
XX F241 Microprocessors KCS Murti

Reminder 1 0 0 1 0 1 Ans=101001

1
3 2 Ans=(231)8

Decimal to hexadecimal
Convert (227)10 to Hexadecimal Integer 227 14 0 3 E Ans=0xE3H Reminder

XX F241 Microprocessors KCS Murti

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.513)10= (0.406517..)8 0 6 5 1 7

XX F241 Microprocessors KCS Murti

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 rs complement : For a number N with n digits, it is defined as (rn-1)-N+1
9s complement of 546700 is (999999-546700)=453299 9s complement of 012398 is (999999-012398)=987601 10s complement of 012398 is 987602 10s complement of 246700 is 753300

XX F241 Microprocessors KCS Murti

1s and 2s complement
1s complement of 1011000 is 1s complement of 0101101 is 0100111 1010010

2s complement of 1101011 is 0010101 2s complement of 0110111 is 1001001

XX F241 Microprocessors KCS Murti

Signed Binary Numbers


Signed magnitude of +7 00000111

Signed magnitude of -7

10000111

Represent +7 in 2s complement form Place 0 in sign bit 0 00000111

Place magnitude in remaining 7 bits Represent -7 in 2s complement form Start with 8 bit code for +7 Invert each bit including the MSB Add 1

00000111 11111000 11111001

XX F241 Microprocessors KCS Murti

Signed binary numbers


Get the magnitude of -7 Its 2s complement is MSB is 1. So magnitude is in 2s complement. Invert all bits including sign. Add 1 11111001

00000110 00000111

XX F241 Microprocessors KCS Murti

Range of numbers in 2s complement

Signed binary 01111111 -----00000001 00000000 11111111 ------10000001 10000000

Decimal +127 +1 Zero -1 -127 -128

XX F241 Microprocessors KCS Murti

Addition
+13 +9 +22 00001101 00001001 00100110 +9 -13 -4 -9 00001001 11110011 11111100 11110111

+13 -9 +4

00001101 11110111 1 00000100 Ignore carry

-13
-22

11110011
11101010

XX F241 Microprocessors KCS Murti

Hexa decimal addition


1 Carry

7A 3F B9

0111 0011 1011 B16

1010 1111 1001 916

7 3 1110 B16

A F 2510 916

XX F241 Microprocessors KCS Murti

Overflow

01110011 11010001 01000100

115 209 68

115 -47 68

Interpreted as unsigned binary (Incorrect)

Interpreted as 2s complement (correct)

XX F241 Microprocessors KCS Murti

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

XX F241 Microprocessors KCS Murti

BCD code..
Advantages
1. Ease of conversion 2. Easy to design the logic circuit. 3. Only the 4 bit groups for the decimal digits 0 to 9 need to be remembered.

Disadvantages:
1. BCD requires more bits

XX F241 Microprocessors KCS Murti

Other binary codes

XX F241 Microprocessors KCS Murti

Grey code
Binary

000 001 010 011 100 101 110 111

Gray Code

000 001 011 010 110 111 101 100

Only one bit changes between successive values

XX F241 Microprocessors KCS Murti

Binary to Grey code conversion


Gn = Bn Gn-1 = Bn Bn-1 Gn-2 = Bn-1 Bn-2 .. .. G1 = B2 B1

XX F241 Microprocessors KCS Murti

Example
Binary to Gray Binary Gray 1 1 0 1 0 0 1 1

Gray to Binary Gray 1 Binary 1

1 0

0 0

1 1

Grey codes
Angular position Measurement where each segment is assigned a binary number

Load

Drive

Shaft encoder

XX F241 Microprocessors KCS Murti

Shaft encoder

Shaft Encoder

XX F241 Microprocessors KCS Murti

The byte, Nibble and Word


Bytes : A byte is a string of eight bits. Nibble: A nibble is a string of four bits. Word : The word size can be defined as the number of bits in the binary word that a digital system operates on. i.e., it depends on the data pathway of the system.

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

XX F241 Microprocessors KCS Murti

Alphanumeric Code

XX F241 Microprocessors KCS Murti

Error detection codes


Parity: An extra bit (parity bit) is added to each word being transmitted. Even parity: P = 0 or 1 at Tx, such that no . of 1s in the code including parity bit is an even number. Odd Parity: P= 0 or 1 , such that no. 1s in the code including parity bit is an odd number.

Example
Let the code group is 1000001 (ASCII code forA), if even parity is used, P=0. so, the new code 10000010 if odd parity is used, P=1 so, the new code 10000011 Where the last bit in the new code is parity bit (P)

Limitations:
1. Position of error cannot be detected. 2. Parity method would not work if two bits were in error.

XX F241 Microprocessors KCS Murti

You might also like