0% found this document useful (0 votes)
14 views18 pages

Lec 5 - NumberConversions

The document covers number conversions between binary, decimal, octal, and hexadecimal systems, including methods for converting fractional and whole numbers. It also explains binary addition and subtraction rules, including the use of 2's complement for subtraction. Practice questions are provided for further understanding of the concepts discussed.

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)
14 views18 pages

Lec 5 - NumberConversions

The document covers number conversions between binary, decimal, octal, and hexadecimal systems, including methods for converting fractional and whole numbers. It also explains binary addition and subtraction rules, including the use of 2's complement for subtraction. Practice questions are provided for further understanding of the concepts discussed.

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/ 18

Lecture-05: 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 =(1110101.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 Octa • 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
Practice Questions
• Convert Binary Fraction to Decimal 0.00110111
• Convert Binary Fraction to Octal 0.1101100101
• Convert Binary Fraction to Decimal 0.011001
• Convert Binary Fraction to Octal 0.111010101
• Convert Decimal Fraction to Binary: 0.625
• Convert Decimal Fraction to binary and octal: 0.4375
• 110001 - 100011 using both methods
• 11111 + 11000

You might also like