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

Lecture 2 Recitation: Number

Systems and Logic Gates

CS-216: Digital Logic Design


September 5, 2015
Summary
• Various number systems suitable for representing
information in digital systems.
– Decimal number system
– Binary number system
– Octal and Hexadecimal number systems
– Codes (Grey code, BCD etc)
• Basic arithmatic operations (e.g. addition and
subtraction of signed numbers) as well as logic
operations (e.g. NOT, AND, OR etc.) and their
representation using logic gates
• Conversion between number systems
• Exercises
Number Systems
• Number System Concepts
– Digits
– Strings
– Radix or Base
– Operations
• Addition and Subtraction
• Multiplication and Division
• Binary numbers: Logic operations (AND, OR, NOT)
Decimal Number System
• Base = 10; Digits = 0, 1, 2, …., 9; Count resets
after 9, and an additional digit added to the
left.
• Weightage (place of the digits in a string):
For a random example of a decimal number,
(XYZ.ABC)10, where X, Y, Z, A, B, C are any decimal
numbers 0 to 9:
X x 102 + Y x 101 + Z x 100 + A x 10-1 +B x 10-2 + C x 10-3
Other Number System
• Binary number system; Base = 2, Digits = 0,1
• Octal number system; Base = 8, Digits = 0, 1, 2,
…, 7
• Hexadecimal number system; Base = 16, Digits
= 0, 1, 2, …., 9, A, B, C, D, E
Weightage for any Number System
For a generic string in a number system with
base = n, if the number is:
ar...a2a1a0 . a-1a-2a-2…..a-p
Then conversion it into decimal equivalent using
weightage is:
ar-1 x nr-1 + …. + a2 x n2 + a1 x n1 + a0 x n0 + a-1 x n-1 + a-2 x n-2
+ … + a-p x n-p
Examples
Decimal Number:
Weightage of (53.64)10:
Base = 10, r = 2, p = 2

Weightage:

5 x 101 + 3 x 100 + 6 x 10-1 + 4 x 10-2


Examples
Binary Number:
Convert (11010.0001)2 into Decimal:
Base = 2, r = 5, p = 4

Weightage:

1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 0 x 2-1 + 0 x 2-2
+ 0 x 2-3 + 1 x 2-4
= 16 + 8 + 2 + 1/16 = (26.0625)10
Examples
Octal Number:
Convert (27.301)8 into Decimal:
Base = 8, r = 2, p = 3

Weightage:

2 x 81 + 7 x 80 + 3 x 8-1 + 0 x 8-2 + 1 x 8-3


= 16 + 7 + 0.375 + 0.001953125 = (23.376953125)10
Examples
Hexadecimal Number:
Convert (AF0.2B)16 into Decimal:
Base = 16, r = 3, p = 2

Weightage:

A(=10) x 162 + F(=15) x 161 + 0 x 160 + 2 x 16-1 + B(=11)


x 16-2
= 2560 + 240 + 0.125 + 0.04296875 = (2800.16796875)10
Reverse Conversion
• In a similar way, a decimal number can
be converted into any number system by
successive division (whole number part)
and multiplication (fractional part) with
the base of the number, and considering
the raminder and carry-over,
respectively.
• This can be better understood by examples.
Examples
Decimal to binary conversion:
Convert (53.25)10 into Binary.
First take whole number Then take the fractional
part: part:

Answer = (110101.01)2
Examples
Decimal to octal conversion:
Convert (53.25)10 into Octal.
First take whole number Then take the fractional
part: part:

Answer = (64.2)8
Examples
Decimal to hexadecimal conversion:
Convert (53.25)10 into Hexadecimal.
First take whole number Then take the fractional
part: part:

Answer = (45.4)16
Examples
Hexadecimal to binary conversion:
(AF0.2B)16 → (?)2
1. Convert (AF0.2B)16 into decimal using
weighted conversion.
2. Convert the result into binary using
successive division/ multiplication by 2.
Examples
Dec Hex Bin

Hexadecimal to binary 0
1
0
1
0000
0001

conversion: 2 2 0010
3 3 0011

(AF0.2B)16 → (?)2 4
5
4
5
0100
0101
6 6 0110
7 7 0111
8 8 1000
(1010) (1111) (0000) . (0010) (1011) 9 9 1001
10 A 1010
= (1010 1111 0000 . 0010 1011) 2 11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Examples
Dec Hex Bin

Binary to hexadecimal 0
1
0
1
0000
0001

conversion: 2 2 0010
3 3 0011

(110111000 . 010101) 2→ (?)16 4


5
4
5
0100
0101
6 6 0110
7 7 0111
(000 1) (1011) (1000) . (0101) (01 00 ) 8 8 1000
9 9 1001

=(1B8.54)16 10
11
A
B
1010
1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Examples
Dec Hex Bin

Octal to binary conversion: 0


1
0
1
0000
0001
2 2 0010
3 3 0011

(235.64)8 → (?)2 4 4 0100


5 5 0101
6 6 0110
7 7 0111
8 8 1000
(010) (011) (101) . (110) (100) 9 9 1001
10 A 1010
= (10011101 . 1101) 2 11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Examples
Dec Hex Bin

Binary to octal 0
1
0
1
0000
0001

conversion: 2
3
2
3
0010
0011
4 4 0100
(1110111 . 010101) 2→ (?)8 5 5 0101
6 6 0110
7 7 0111
( 00 1) (110) (111) . (010) (101) 8 8 1000
9 9 1001

=(167.25)8 10
11
A
B
1010
1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Arithmatic Operations
Dec Hex Bin
• Addition 0 0 0000
1 1 0001
2 2 0010
AF.78C 3 3 0011
+ FEF.34 4 4 0100
5 5 0101
-------- 6 6 0110
7 7 0111

• Subtraction 8 8 1000
9 9 1001
10 A 1010

B3F.7C 11 B 1011
12 C 1100
- 18F.34
13 D 1101
-------- 14 E 1110
15 F 1111
Arithmatic Operations
Dec Hex Bin

• Multiplication 0
1
0
1
0000
0001
2 2 0010
3 3 0011
1 2 4 4 0100
5 5 0101
x 3 F
6 6 0110
-------- 7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Arithmatic Operations
Dec Hex Bin

• Division 0
1
0
1
0000
0001

____ 2 2 0010
3 3 0011
3 ) DEAD ( 4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
Arithmatic Operations
Dec Hex Bin

• Subtraction 0 0 0000
1 1 0001
2 2 0010
3 3 0011
B3F 4 4 0100
5 5 0101
- 18F 6 6 0110

----- 7 7 0111
8 8 1000
9 9 1001
10 A 1010
18F 11 B 1011
12 C 1100
- B3F 13 D 1101

----- 14 E 1110
15 F 1111
Radix and Diminished Radix Complement
String = N;
Base = n
Number of digits = r

(n - 1)’s complement of N , or Diminished Radix


Complement:
(nr - 1) – N

n ’s complement of N , or Radix Complement:


(nr - 1) – N + 1
Subtraction using Radix Complement
Dec Hex Bin
• Subtraction 0 0 0000
B3F
1 1 0001
- 18F
----- 2 2 0010
3 3 0011
n = 16 4 4 0100
r=3 5 5 0101
6 6 0110
16’s complement of 0x18F:
7 7 0111
(163-1)- 18F + 1 = FFF – 18F + 1 = E71 8 8 1000
9 9 1001
B3F 10 A 1010
+ E71
11 B 1011
-----
1)9B0 Answer = 9B0 12 C 1100
13 D 1101
If no carry-over, then take 10’s complement of 14 E 1110
the result, and put a minus sign besides it.
15 F 1111
Subtraction using 2’s Complement
Dec Hex Bin
• Subtract using 2’s complement
1011010 0 0 0000
- 1100110 1 1 0001
---------- 2 2 0010

n=2 3 3 0011
r=7 4 4 0100
5 5 0101
2’s complement of 1100110:
6 6 0110
(27-1)- 1100110 + 1 = 1111111 – 1100110 + 1 = 0011010 7 7 0111
Easier way to calculate: Flip all bits and add 1 to
result. 8 8 1000
9 9 1001
1011010
+ 0011010 10 A 1010
---------- 11 B 1011
0)1110100 Result = 1110100
12 C 1100

Since no carry-over, then take 2’s complement of the 13 D 1101


result again, and put a minus sign besides it:
14 E 1110
Answer = - 0001100
15 F 1111
(Bitwise) Logic Operations (Binary number system only)

• Operands (inputs) and result (output) can have


either 0 or 1 value. Also referred to as logic 0/logic
1, ‘0’/’1’, and false/true.
• Basic Operations:
– AND
– OR
– NOT
• Derived Operations
– NAND
– NOR
– XOR
– XNOR
(Bitwise) Logic Operations (Binary number system only)

• AND operation:
Output is logic ‘1’ if all inputs are ‘1’. Even if a
single input is ‘0’, the output is ‘0’.
INPUT OUTPUT
A B Q = A AND B
0 0 0
0 1 0
1 0 0
1 1 1
(Bitwise) Logic Operations (Binary number system only)

• OR operation:
Output is logic ‘1’ if any of the inputs is ‘1’.
The output is ‘0’ if all inputs are ‘0’
INPUT OUTPUT
A B Q = A OR B
0 0 0
0 1 1
1 0 1
1 1 1
(Bitwise) Logic Operations (Binary number system only)

• OR operation:
Unary operator; Output is logic ‘1’ if input is
‘0’, and vice versa.

INPUT OUTPUT
A Q = NOT(A)
0 1
1 0

You might also like