0% found this document useful (0 votes)
11 views41 pages

Lec 5 - 6 - NumberConversion&LogicGates

The document covers number conversions between binary, decimal, octal, and hexadecimal systems, including methods for addition and subtraction in binary and octal. It also introduces logic gates, their functions, and how they are implemented in hardware using transistors. Key logic gates discussed include AND, OR, NOT, NAND, NOR, and XOR, along with their truth tables.

Uploaded by

bscs23091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views41 pages

Lec 5 - 6 - NumberConversion&LogicGates

The document covers number conversions between binary, decimal, octal, and hexadecimal systems, including methods for addition and subtraction in binary and octal. It also introduces logic gates, their functions, and how they are implemented in hardware using transistors. Key logic gates discussed include AND, OR, NOT, NAND, NOR, and XOR, along with their truth tables.

Uploaded by

bscs23091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Lecture-05,06: Number Conversions

and Logic Gates


Instructor: Mehwish Ghafoor
[email protected]
Fractional Binary Conversions
• Binary to Decimal
• (1101.011)2=(?)10

1X23 + 1X22 + 0X21 + 1X20+ 0X2-1+1X2-2+1X2-3


13+0+1/4+1/8
13+3/8
13.375
Binary to Octal
• (10110110.0101)2=(?)8

10110110.0101
421 421 421 421 421
010 110 110 . 010 100
2 6 6 . 2 4

(266.24)8
Binary to HexaDecimal
• (1101011.00101)2=(?)16

1101011.00101
8421 8421 . 8421 8421
0110 1011 0010 1000
6 B . 2 8

(6B.28)16
Decimal to Binary
(48.125)10 =(?)2
(.125)10=(?)2
Integer Fraction
Divide by 2 Multiply by 2
.125x2=0 ▪ 0.125 * 2 = 0.25
▪ Integer part: 0
2 48 ▪ Fractional part: 0.25
2 24- 0 .250x2=0 • 0.25 * 2 = 0.5
2 12 - 0 • Integer part: 0
• Fractional part: 0.5
2 6 -0 .500x2=1 • 0.5 * 2 = 1.0
2 3- 0 • Integer part: 1
1- 1 1.00000 • Fractional part: 0.0

(.125)10=(0010)2
(48)2=110000 (48.125)10 =(110000.0010)2
Decimal to Binary
(117.65625)10 =(?)2

Integer Fraction
Divide by 2 Multiply by 2
Decimal to Binary ▪ 0.65625 * 2 = 1.31250
▪ Integer part: 1
▪ Fractional part: 0.31250
(117.65625)10 =(?)2 • 0.31250 * 2 = 0.62500
(.65625)10=(?)2 • Integer part: 0
Integer Fraction • Fractional part: 0.62500
Divide by 2 Multiply by 2 .65625x2=1 • 0.62500 * 2 = 1.25000
• Integer part: 1
2 117 1.31250x2=0 • Fractional part: 0.25000
2 58- 1 • 0.2500 * 2 = 0.5000
.62500x2 =1 • Integer part: 0
2 29 - 0 • Fractional part: 0.5000
2 14 - 1 1.25000 x2=0 • 0.500 * 2 = 1.000
2 7- 0 • Integer part: 1
.50000 x2 =1 • Fractional part: 0.000
2 3- 1
1- 1 1.00000
(117)2=1110101
(. 65625)10=(10101)2
(117.65625)10 =(1110001.10101)2
Decimal to Octal
▪ 0.65 * 8 = 5.20
(.65)10=(?)8 ▪ Integer part: 5
(48.65)10 =(?)8
▪ Fractional part: 0.20
.65 x 8 = 5
• 0.20 * 8 = 1.60
Integer Fraction • Integer part: 1
5.20 x 8=1
Divide by 8 Multiply by 8 • Fractional part: 0.600
• 0.600 * 8 = 4.80
8 48 1.60 x 8 =4
• Integer part: 4
6- 0 • Fractional part: 0.80
4.80 x8= 6
• 0.80 * 8 = 6.40
• Integer part: 6
6.40 x 8= 3
(48)10= (60)8 • Fractional part: 0.40
• 0.4 * 8 = 3.20
3.20 x 8= 1
• Integer part: 3
• Fractional part: 0.20
1.60 x 8
• 0.2 * 8 = 1.60
• Integer part: 1
(. 65)10=(.51463)2
• Fractional part: 0.60
(48.65)10 =(60.51463)8
▪ 0.65 * 8 = 5.20
▪ Integer part: 5
▪ Fractional part: 0.20
Decimal to Octal • 0.20 * 8 = 1.60
• Integer part: 1
• Fractional part: 0.600
(.65)10=(?)8 • 0.600 * 8 = 4.80
(48.65)10 =(?)8 • Integer part: 4
.65 x 8 = 5 • Fractional part: 0.80
Integer Fraction • 0.80 * 8 = 6.40
Divide by 8 Multiply by 8
5.20 x 8=1 • Integer part: 6
• Fractional part: 0.40
8 48 1.60 x 8 =4 • 0.4 * 8 = 3.20
6- 0 • Integer part: 3
4.80 x8= 6 • Fractional part: 0.20
• 0.2 * 8 = 1.60
6.40 x 8= 3 • Integer part: 1
(48)10= (60)8
• Fractional part: 0.60
3.20 x 8= 1 Continue multiplying
till you get a zero or
values start repeating.
1.60 x 8
(. 65)10=(.51463)2
(48.65)10 =(60.51463)8
Decimal to Hexadecimal
(48.65)10 =(?)16

• Method remains the same.


• Do this yourself.
Binary Addition
• Rules for binary addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (with 1 carry)
1 + 1 + 1 = 1 (with 1 carry)

Examples:

1 1 1 1 Carry 1 1 Carry
1 1 0 1 1 1 0 0 1
+ 1 0 1 0 1 + 1 0 1 1
1 1 0 0 0 0 1 0 1 0 0
Binary Subtraction 1 1
- 1 0
0 1
• Rules for binary subtraction
0-0=0
0 - 1 = will take 1 borrow , gives 10
1-0=1 0 1
1-1=0 1 1 0
- 1 0 1
Examples: 0 0 1
Binary Subtraction 1 1
- 1 0
0 1
• Rules for binary subtraction
0-0=0
0 - 1 = will take 1 borrow , gives 10
1-0=1 0 1
1-1=0 1 1 10

- 1 0 1
Examples: 0 0 1

0 1 1 0 1 10

1 10 10 10 10 10
1 1
- 0 1 1 1 - 0 1 1 1
0 0 0 1 0 0 1 1
Binary Subtraction 1 1
- 1 0
0 1
• Rules for binary subtraction
0-0=0
0 - 1 = will take 1 borrow , gives 10
1-0=1 0 1
1-1=0 1 1 10

- 1 0 1
Examples: 0 0 1

0 1 1 0 1 10 0 1 1
1 10 10 10 1 10 1 10 1 1 10 10 10

- 0 1 1 1 - 0 1 1 1 - 0 0 1 1 1
0 0 0 1 0 0 1 1 1 0 0 0 1
Binary Subtraction
• Another method is taking 2’s complement.
• Take 2’s complement of the number to be subtracted.
• Perform addition
• Check if there is an end carry in the answer, if so, discard it and the remaining number is the
answer, otherwise the answer is negative so again take the 2’s complement of the answer.
• Example: (0010 – 0111)
• Take 2’s of 0111
• 2’s complement= 1’s complement + adding 1
• 1’s complement= flipping 0’s to 1 and vice versa
• 1’s complement of 0111= 1000
• Adding 1 we get 2’s complement 1 0 0 0
+ 1
2’s Complement
1 0 0 1
Binary Subtraction
• The question is : 0010 - 0111
• 2’s complement of 0111= 1001
• Now add the two highlighted numbers.
0 0 1 0
+ 1 0 0 1
1 0 1 1

• There is no end carry, so again take 2’s complement of 1011 .


• 0100+1= 0101
• So, 0010 – 0111= 0101
Binary Subtraction
• Solve 0111-0010
• Take 2’s complement of 0010
▪ 1101+1= 1110 1 1
0 1 1 1
• Now add 0111 and 1110
+ 1 1 1 0
• 1 is carry here, so discard it. 1 0 1 0 1

• 0111-0010= 0101
Octal Addition
• (634)8 + (475)8
• Octal has a range from 0-7 digits, so while adding if you get a number greater
than 7, it will be divided by 8 to get its octal value.

1 1 8 9
6 3 4 1-1
+ 4 7 5
1 3 3 1 8 11
1-3

(1331)8
Octal Subtraction
• Base 8, borrow will be 8
253
• (253)8 – (167)8
−1 6 7
064

• (64)8
Octal Subtraction
• (2304)8 – (1065)8
2304
−1 0 6 5
1217
• Answer is 1217
Addition/Subtraction of Binary Fractions

1101.11 1101.01
+0100.10 −0100.10
10010.01 1000.11
Addition/Subtraction of Octal Fractions

57.23 67.5
+12.43 +45.6
7 1 .66 135.3

64.5
−40.6
23.7
Logic Gates
• Logic gates are the building blocks of all the circuits in a computer.

• The computer/smartphone you are using now is made-up on these


logic gates.

• Combinations of these gates are used to implement everything in a


microprocessor.
Logic Gates
• To implement a logic gate in hardware, you use a transistor.
• Transistors are all enclosed in an “IC”, or integrated circuit.
• Millions of transistors reside in a computer.

• Logic Gates are collections of transistors that electrically mimic a


particular logic function. Combinations of these gates are used to
implement everything in a microprocessor.
Basic Gates
AND, OR, NOT
Derived Gates
NAND , NOR , XOR
AND Gate
• The AND gate implements the Boolean AND function where the output only is logical 1
when all inputs are logical 1.
• The standard symbol and the truth table for a two input AND gate is:

A B A.B
0 0 0
0 1 0
1 0 0
1 1 1
OR Gate
• The OR gate implements the Boolean OR function where the output is logical 1 when any
of the input is logical 1.
• The standard symbol and the truth table for a two input OR gate is:

A B A+B
0 0 0
0 1 1
1 0 1
1 1 1
NOT Gate
• The NOT gate implements the Boolean NOT function where the output is the inverse of
the input.
• The standard symbol and the truth table for the NOT gate is:

A 𝐴
0 1

1 0
NAND Gate
• The NAND gate is an AND gate followed by a NOT gate. The output is logical 1
when one of the inputs are logical 0.
• The standard symbol and the truth table for the NAND gate is:

A B 𝐴. 𝐵
0 0 1
0 1 1
1 0 1
1 1 0
NOR Gate
• The NOR is a combination of an OR followed by a NOT gate. The output is logical 1 when non of
the inputs are logical 1.
• The standard symbol and the truth table for the NOR gate is:

A B 𝐴+𝐵
0 0 1
0 1 0
1 0 0
1 1 0
XOR Gate (Exclusive OR)
• The XOR gate produces a logic 1 output only if its two inputs are different.
If the inputs are the same, the output is a logic 0.
• The XOR symbol is a variation on the standard OR symbol. It consists of a
plus (+) sign with a circle around it.

A B (A⊕B)
0 0 0
0 1 1
1 0 1
1 1 0
Logic Gates: Basic & Derived
x
• NOT x
x xy x xyz
• AND y y
z
x x+y x x+y+z
y
• OR y z
x xy
• NAND y
x+y
• NOR x
y
• XOR x xÅy
y
Boolean Expression and Circuit Design

1) ( A • B) = A + B A A
B = B C

A B A.B 𝑨. 𝑩 𝑨 𝑩 𝑨+𝑩
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0
Truth Table

L.H.S=R.H.S
Boolean Expression and Circuit Design

1) ( A • B) = A + B A A A+B

B = B C

2) ( A + B) = A • B A
= A
C
B B

3) A+ B = A • B A
B = A
B C

A A
4) A• B = A+ B B = B C

Write truth tables to prove the above Boolean expressions.


Output of Circuit
• Find the output of the following circuit

x
x xy xy
y
y
___
__
• Answer: xy
• Or (xy)
Output of Circuit
• Find the output of the following circuit

x x+y
y (x+y)y

y y

__
• Answer: (x+y)y
• Or (xy)y
Designing Circuits from Expressions
• Design circuits for the following Boolean expressions
__
a) x+y

x x+y
x
y
Proving Expressions
• Prove the following expression:
p Å q  (p  q) _____
 ¬(p  q)
p Å q  (p + q) (pq)
p q pq pq pq (p  q)  ¬(p  q) pÅq

0 0 0 0 1 0 0
1 0 1 0 1 1 1
0 1 1 0 1 1 1
1 1 1 1 0 0 0

L.H.S=R.H.S
Proving Expressions
• Prove the following expression:
p Å q  (p  q)  ¬(p  q)

p q pq pq pq (p  q)  ¬(p  q) pÅq

0 0 0 0 1 0 0
1 0 1 0 1 1 1
0 1 1 0 1 1 1
1 1 1 1 0 0 0

L.H.S=R.H.S
Draw the circuit for the R.H.S expression.
Class Task
• Prove the following
____
expression by truth table and design its circuit.
• x Å y  (x + y)(xy)
Class Task
• Prove the following
____
expression by truth table and design its circuit.
• x Å y  (x + y)(xy)
x y xÅy
1 1 0
1 0 1
0 1 1

x x+y 0 0 0

y (x+y)(xy)
xy xy

You might also like