0% found this document useful (0 votes)
9 views36 pages

Lec 3 - NumberSystems - II

The lecture covers the conversion between different number systems, including binary, octal, decimal, and hexadecimal. It explains methods for converting between these bases, the significance of these conversions in computing, and the challenges associated with them. Additionally, it emphasizes the importance of understanding number systems for problem-solving in fields like computer science and engineering.

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)
9 views36 pages

Lec 3 - NumberSystems - II

The lecture covers the conversion between different number systems, including binary, octal, decimal, and hexadecimal. It explains methods for converting between these bases, the significance of these conversions in computing, and the challenges associated with them. Additionally, it emphasizes the importance of understanding number systems for problem-solving in fields like computer science and engineering.

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

Lecture: 03: Number Systems

Instructor: Mehwish Ghafoor


[email protected]
Converting Binary to Octal
• Mark groups of three (from right)
• Convert each group

10101011 010 101 011


2 5 3

10101011 is 253 in base 8

Why does this work??

2
Converting Binary to Octal

• Mark groups of three (from right)


• Convert each group

10101011 010 101 011


2 5 3

10101011 is 253 in base 8

Why does this work??


Since 23=8, It takes 3 base2 digits to combine to make a base 8 digit.
3
Binary to Octal
• Try these:
• 111100
• 100101
• 111001
• 1100101
• Hint: when the leftmost group has fewer than three digits, fill
with zeroes from the left:
• 1100101 = 1 100 101 = 001 100 101
• 110011101

4
Converting Binary to Hexadecimal

• Mark groups of four (from right)


• Convert each group

10101011 1010 1011


A B

10101011 is AB in base 16

Why does this work??


Since 24=16, It takes 4 base2 digits to combine to make a base 16 digit.
5
Binary to Hexadecimal
• Try these:
• 11011100
• 10110101
• 10011001
• 110110101
• Hint: when the leftmost group has fewer than four digits, fill
with zeroes on the left:
• 110110101 = 1 1011 0101 = 0001 1011 0101
• 1101001011101

6
Binary to Hexadecimal
• The answers are:
• 110111002 = DC16
• 101101012 = B516
• 100110012 = 9916
• 1101101012 = 1B516
• 1 1010 0101 11012 = 1A5D16

7
Octal to Binary
• Converting from Octal to Binary is just the inverse of Binary to Octal.

• For each octal digit, translate it into the equivalent three-digit binary
group.

• For example, (45)8=(100101)2

8
Hexadecimal to Binary

• Converting from Hexadecimal to Binary is the inverse of Binary to


Hexadecimal.

• For each “hex” digit, translate it into the equivalent four-digit binary
group.

• For example, (45)16=(01000101)2

9
Octal/Hexadecimal to Binary Exercises
• Convert each of these to binary:
• 638
• 12316
• 758
• A2D16
• 218
• 3FF16

10
Octal/Hexadecimal to Binary Exercises

• The answers are:


• 638 = (110011)2
• 12316 = (100100011)2 (drop leading 0s)
• 758 = (111101)2
• A2D16 = (110000101101)2
• 218 = (10001)2
• 3FF16 = (1111111111)2

11
Octal to decimal
• Convert (75)8 to decimal
• (75)8 = (7×81 + 5×80)

= (7×8 + 5× 1)
= (56+5)
= 6110
• Another method is converting octal to binary first and then to decimal.

12
Converting Decimal to Other Bases

Method for converting number in base 10 to other bases

REPEAT
• While (the quotient is not zero)
o Divide the decimal base number by the new base
o Make the remainder the next digit to the left in the
answer
o Replace the original decimal number with the quotient

13
Converting Decimal to Binary
What is (28)10 in base 2?
Method 1
2 28
2 14- 0
2 7 -0
2 3 -1
2 1- 1
0-1

• (28)10 = (11100)2

14
Converting Decimal to Binary
What is (28)10 in base 2?
Method 1 Method 2
2 28
2 14- 0 Using power of 2….
2 7 -0
2 3 -1
2 1- 1
0 -1

• (28)10 = (11100)2

15
Converting Decimal to Octal
What is (1988)10 in base 8?
8 1988
8 248 - 4
8 31- 0
3 - 7

• (1988)10 = (3704)8

16
Decimal to octal
• Convert 6810 to octal

17
Decimal to octal
• Convert 6810 to octal
8 68
8 8-4
1- 0

• (68)10 = (104)8

18
Decimal to octal
• Convert 11710 to octal
8 117
8 14 - 5
1- 6

• (117)10 = (165)8

19
Decimal to Hexadecimal
• Convert (213)10 to Hex
16 213
13 - 5

• 13=D

• (213)10 = (D5)H

20
Decimal to Hexadecimal
• Convert (117)10 to Hex

21
Decimal to Hexadecimal
• Convert (117)10 to Hex
16 117
7-5

• (117)10 = (75)H

22
Hexadecimal to Octal
• Converting from Hexadecimal to Octal is a two-
part process.
• First convert from “hex” to binary, then regroup the bits from groups
of four into groups of three.
• Then convert to an octal number.

23
Hexadecimal to Octal

• For example:
(4A3)16
= 0100 1010 00112
= 010 010 100 0112
= 22438

24
Octal to Hexadecimal

• Converting from Octal to Hexadecimal is a similar two-


part process.
• First convert from octal to binary, then regroup the bits from groups of three into
groups of four.
• Then convert to a hexa number.

25
Octal to Hexadecimal

• For example:
(371)8
= 011 111 0012
= 1111 10012
= F916

26
Octal/Hexadecimal Homework

• Convert each of these:


• 638 = ________16
• 12316 = ________8
• 758 = ________16
• A2D16 = ________8
• 218 = ________16
• 3FF16 = ________8

27
Applications of Octal and Hexadecimal
• Octal and hexadecimal offer a more compact representation of large
binary numbers, making them easier to read and work with.
• They align well with the grouping of bits in modern computing
architectures.
• Computers commonly use hexadecimal to represent memory addresses
and data because each digit corresponds directly to four bits (half a
byte).
• Memory dumps and debugging tools often use hexadecimal to display
binary data more precisely.

28
Applications of Octal and Hexadecimal
• Programming: Hexadecimal is frequently used in programming to
represent memory addresses, binary data, and ASCII characters.
• Color Codes: Hexadecimal codes are used to specify colors in HTML, CSS,
and graphics software (RGB values).
• Network Addresses: MAC addresses and IP addresses are often written
in hexadecimal.
• Assembly Language: Assembly programming languages often use
hexadecimal notation for memory addresses and opcodes.

29
Conclusion
• Complex Conversions Between Bases:
• Converting between different number bases, especially from higher
to lower bases, can become complex and require careful calculations.
• The process involves division and remainder operations, which can be
time-consuming for larger numbers.
• Errors During Conversions:
• Mistakes during manual conversions can lead to incorrect results.
• It's important to double-check calculations and maintain accuracy,
especially for critical applications like programming and engineering.

30
Conclusion
• Human Readability:
• Binary numbers can become lengthy and challenging to read, making
comprehension difficult for humans.
• Hexadecimal and octal representations offer a more compact and
readable alternative for binary data.
• Programming Challenges:
• Certain programming tasks, like implementing arithmetic operations,
can be more complex when dealing with non-decimal bases.
• Careful handling of carry, borrow, and overflow is required in binary
arithmetic.

31
Conclusion
• Loss of Precision:
• When converting between bases, there might be a loss of precision if
the target base cannot accurately represent the original value.
• For example, decimal fractions might not convert precisely to binary
fractions.
• Significance of Zeroes:
• Leading zeroes in binary or octal numbers might not have the same
significance as in decimal, leading to potential confusion.

32
Conclusion
• Mixed Radix Systems:
• Some systems use mixed radices, combining different bases within the
same representation (e.g., time units like hours, minutes, and seconds).
• Converting between mixed radix systems can be more complex.
• Importance of Understanding:
• While conversion tools and calculators exist, understanding the underlying
principles of number systems aids problem-solving and error detection.
• Proficiency in converting between bases is essential in fields like computer
science, engineering, and mathematics.

33
Conclusion
• Education and Practice:
• Regular practice and exposure to different bases can improve
conversion skills and help overcome challenges.
• Building a strong foundation in number systems enhances
computational abilities.
• Conclusion:
• Working with different number systems presents challenges,
from complex conversions to maintaining accuracy. A solid
understanding of these challenges, along with consistent
34
Summary
• We did twelve different number base conversions among the four
different bases (2,8,10, and 16).

• Binary/Octal/Hexa to Decimal
• Binary to Octal/Hexa
• Octal/Hexa to Binary
• Decimal to Binary/Octal/Hexa
• Hexa to Octal
• Octal to Hexa

35
References
• https://www.slideserve.com/alvis/binary-and-other-number-bases
• https://cs.slu.edu
• https://www.cs.cornell.edu
• https://electronicscoach.com/number-system.html

36

You might also like