Lec 3 - NumberSystems - II
Lec 3 - NumberSystems - II
2
Converting Binary to Octal
4
Converting Binary to Hexadecimal
10101011 is AB in base 16
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.
8
Hexadecimal to Binary
• For each “hex” digit, translate it into the equivalent four-digit binary
group.
9
Octal/Hexadecimal to Binary Exercises
• Convert each of these to binary:
• 638
• 12316
• 758
• A2D16
• 218
• 3FF16
10
Octal/Hexadecimal to Binary Exercises
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
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
25
Octal to Hexadecimal
• For example:
(371)8
= 011 111 0012
= 1111 10012
= F916
26
Octal/Hexadecimal Homework
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