Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

CKV

Digital Electronics and Computer Organization


EEE C391/ECE C391/CS C391

Digital Design
EEE F215/ECE F215/INSTR F215/CS F215

Lecture 2: Number systems


CKV

Number systems
For Base - r system (anan-1…. a1a0. a-1a-2..a-m)r

an x rn + an-1 x rn-1 …… a1 x r1 + a0 x r0 + a-1 x r-1 +…..a-m x r-m

Find the decimal equivalent of

(123.4)8 1 x 82 + 2 x 81 + 3 x 80 + 4 x 8-1 = 83.5

(B2.4)16
CKV

Number Base conversions


Typical conversions
Base-10 to Base-r
Convert (49)10 to ()2 2 49 Remainder
2 24 1 LSB
2 12 0
2 6 0
2 3 0
2 1 1
(110001)2
0 1 MSB
CKV

Number Base conversions


Typical conversions
Base-10 to Base-r (fraction)
Convert (0.49)10 to ()2 Integer
0.49 x 2 = 0.98 0
0.98 x 2 = 1.96 1
0.96 x 2 = 1.92 1
0.92 x 2 = 1.84 1

(0.49)10 = (0.11111….)2 Limited to required number of digits


CKV

Number Base conversions


Typical conversions
Base-r to Base-10
Convert (110110)2 to ()10
1 x 25 + 1 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20
1 x 32 + 1 x 16 + 0 x 8+ 1 x 4+ 1 x 2 + 0 x 20
1 x 32 + 1 x 16 + 0 x 8+ 1 x 4+ 1 x 2 + 0 x 20
54
CKV

Number conversions
Other conversions

Binary to octal Octal: base 8 digits used 0-7

1110001010101

001 110 001 010 101

1 6 1 2 5

(1110001010101)2 (16125)8
CKV

Number conversions
Other conversions

octal to binary Octal: base 8 digits used 0-7

6373
6 3 7 3

110 011 111 011

(6373)8 (110011111011)2
CKV

Number conversions
Other conversions
Binary to Hexadecimal Hexa: base 16 digits used 0-F

1110001010101

0001 1100 0101 0101

1 C 5 5
(1110001010101)2 (1C55)16
More conversions in detail in Saturdays Tutorial
CKV

Complements
Used to simplify Subtraction

Diminished radix complement


Given a number N in base r having n digits (r-1)’s complement is
defined as (rn-1-N)

In case of decimal it is called 9’s complement

9’s complement of 865 is 103 -1-865 = 999 - 865 = 134

In case of binary it is called 1’s complement


1’s complement of 1011 is 24 -1-1011 = 1111-1010 = 0100
CKV

Complements
Radix complement
Given a number N in base r having n digits r’s complement is defined as
(rn-N)
In case of decimal it is called 10’s complement

10’s complement of 865 is 103 -865 = 1000-865 = 135

10’s complement = 9’s complement + 1

In case of binary it is called 2’s complement


2’s complement of 1011 is 24 -1011 = 10000-1011 = 0101
2’s complement = 1’s complement + 1
CKV

Complements
Addition 7+3
7  0111
3  0011

1 1 1
0 1 1 1
0 0 1 1
1 0 1 0
1010  (10)10
CKV

Complements
Subtraction using complement 7-3
7  0111 0111
3  0011 2’s complement 1101

1 1 1 1
0 1 1 1
1 1 0 1
0 1 0 0
Carry generated
0100  (4)10
CKV

Complements
Subtraction using complement 3-7
3  0011 0011
7  0111 2’s complement 1001

0 0 1 1
0 0 1 1
1 0 0 1
1 1 0 0
Carry not generated
1100  ?
CKV

Complements
If final Carry not generated 1100
Answer is = -(2’s complement of result)
-(2’s complement of 1100)
-(0100)
-(4)

If final carry generated then Answer = result of addition

If final carry NOT generated then Answer = -(2’s complement of


result of addition)
CKV

Signed numbers
Need for notation to represent negative values
MSB 1 indicates negative
MSB 0 indicates positive

Representation of negative numbers


Signed 2’s complement representation (widely used)

Signed 1’s complement representation

Signed magnitude representation


CKV

Signed numbers
4-bit numbers Signed Signed 1’s Signed 2’s
magnitude complement complement
0000 +0 +0 +0
0001 +1 +1 +1
0010 +2 +2 +2
0011 +3 +3 +3
0100 +4 +4 +4
0101 +5 +5 +5
0110 +6 +6 +6
0111 +7 +7 +7
If MSB 0 same value as binary
CKV

Signed numbers
4-bit numbers Signed
magnitude
1000 -0
1001 -1
1010 -2 The first bit indicates sign rest
3-bits indicates magnitude
1011 -3
1100 -4 Two representations for 0
1101 -5
1110 -6
1111 -7
CKV

Signed numbers
Take 1’s complement Signed 1’s
complement
1000 0111 -7
1001 0110 -6
1010 0101 -5
1011 0100 -4
1100 0011 -3
1101 0010 -2
1110 0001 -1
1111 0000 -0
Two representations for zero
CKV

Signed numbers
Take 2’s complement Signed 2’s
complement
1000 1000 -8
1001 0111 -7
1010 0110 -6
1011 0101 -5
1100 0100 -4
1101 0011 -3
1110 0010 -2
1111 0001 -1
CKV

Signed numbers
4-bit unsigned number has range 0 to 15

Ranges for signed numbers n-bit


4-bit signed magnitude -7 to +7 -2n-1 – 1 to +2n-1 – 1

4-bit signed 1’s complement -7 to +7 -2n-1 – 1 to +2n-1 – 1

4-bit signed 2’s complement -8 to +7 -2n-1 to +2n-1 – 1


CKV

Binary Codes - BCD


Binary system used in digital system

Humans accustomed to decimal system

BCD code acts as a bridge between the two

BCD – Binary coded decimal


CKV

Binary Codes - BCD


Consider example 7698
0000 0
0001 1 7 6 9 8
0010 2
0011 3
0100 4
BCD code
0101 5
0110 6
0111 7
1000 8
1001 9
CKV

Binary Codes - BCD


General digital systems
User enters decimal  BCD i/p Binary i/p  compute in binary
 Binary o/p  BCD o/p  Decimal output shown to user

Some systems work directly on BCD (IBM Power6)

User enters decimal  BCD i/p compute in BCD  BCD o/p 


Decimal output shown to user

Used in financial applications What could be the reason ?


CKV

Binary Codes - BCD


BCD addition
4+5 4 0100
5 0101
9 1001 Expected Result

4+8 4 0100
8 1000
1100 Is this expected Result ?

Expected answer is BCD of 12 0001 0010


CKV

Binary Codes - BCD


BCD addition
4+8 4 0100
8 1000
Greater than 9 1100 Add correction of +6
0110
00010010
1 2
CKV

Binary Codes - BCD


BCD addition
9+9 9 1001
9 1001
Carry out generated 1 0 0 1 0 Expected result ?
0110 Add correction of +6
00011000
1 8

After addition if carry out is generated or if sum is greater


than 9 there is need for correction
CKV

Other codes
Other decimal codes: 2421 code, Excess-3 code, 84-2-1 code

Other codes: Gray code, ASCII code

Reading assignment
CKV

Next Class
Boolean Algebra

You might also like