Unit 2: Digital Information Name: ________________________
Lesson 2: Binary Number System
Decimal vs Binary
• ______________ number system is referred to as ________________ and has 10 digits: _________
• ______________ number system is referred to as ________________ and has 2 digits: _________
• Understanding and performing conversions between decimal and binary number systems provide
insights into how computers process and store data:
o Learning to convert between decimal and binary helps
programmers understand how values are stored and
manipulated within a computer's memory.
o Understanding how to convert between decimal and binary
can help optimize storage space and design more efficient
data compression algorithms.
o Converting between decimal and binary is essential for
understanding how data is encoded and decoded during
online communication.
o Converting between decimal and binary is crucial for
designing and understanding digital circuits and logic
gates.
o Converting between decimal and binary exercises logical thinking and problem-solving skills.
• In today's digital world, basic knowledge of binary and its conversion from/to decimal is a form of
digital literacy.
• While we don't typically perform manual conversions in day-to-day tasks due to technology, a
foundational understanding of converting between decimal and binary can be useful in understanding
computer-related concepts.
Representing Numbers
• The decimal number system and has 10 digits: 0 – 9
• We can represent every number we can think of with _____________
• Every number we can think of can be broken down into a base-10 representation
Breakdown the following decimal numbers into their base-10 representation
84 225 1376
• As you can infer, we can represent any whole number we know with its base-10 equivalent.
• In the binary number system, representing numbers works similarly, just with __________ instead of 10.
• The binary number system has 2 digits: 0 and 1
• We can still represent every whole number we know (and even the decimals) with just these two digits
• Each digit is a place holder like the decimal representation above, it is just that the base number is now
"2" instead of 10.
Breakdown the following binary numbers into their base-2 representation:
1101 1001 100
• Each position is called a bit and they are commonly grouped together in bytes (8 bits)
• On paper, we sometimes put a space between a byte which makes are group of 4 bits (called a
___________) that are easier to read
Binary
8th 7th 6th 5th 4th 3rd 2nd 1st
Position
Base 2
Decimal
Representation
• To differentiate between the decimal number 1101 (one thousand one hundred and one) and the binary
number 1101, we use a subscript system:
• ___________ is one thousand one hundred and one (1,101)
• ___________ is the binary number 1101 which is thirteen in
decimal (13)
Binary to Decimal Conversions
When converting from binary to decimal, think of this: Which base-2 positions are “switched on”?
1010 1101 0010 1000
What is the largest number we can hold in one byte?
1111 1111
__________ numbers can be represented using one byte: ______________
Binary to Decimal Conversion: Practice
0001 0101 0011 0101
0101 0110 0001 1111
Decimal to Binary Conversions
• For this algorithm, you will be repeatedly dividing a number by 2
• When dividing by 2, you have two options for a remainder: 0 or 1
• These remainders will eventually make up our binary number
20 45
Decimal to Binary Conversion: Practice
70 101
193 204
Signed Numbers
• Binary digits can represent not only whole numbers but also other forms of data
• For example, to represent signed integers, we can use the leftmost bit of a number to represent the sign:
o 0 meaning _____________
o 1 meaning _____________
• The remaining bits are used to represent the magnitude of the value.
For example, to represent the quantity −49, we could use seven binary digits with 1 bit for the sign and 6 bits for
the magnitude:
How does the computer know that this is the number −49 instead of 113 (which would be the value if we
counted the left most digit as 26)?
The computer doesn't!
• A sequence of binary digits can have many different interpretations, and there is no fixed, predetermined
interpretation given to any binary value.
• The meaning of a binary number stored in memory is based solely on ________________ in which it is
being used.
• In other words, if the computer is expecting a positive or a negative number, it will read that left most
digit as a sign.
• This might seem strange, but we have it all the time in the English language: For example, what if I
asked you what the word “ball” means?
o
o
• Which interpretation is correct? We cannot say without knowing the
context in which the word is used.
• This is the same for the computer, there will be instructions given to
the computer (also in binary) to let it know what type of number to expect.
Decimal Numbers
• How can numbers with decimal points be represented in binary?
• The most intuitive way might be to first treat the number as a whole number, and then always insert a
decimal point at the same point in its decimal equivalent.
• Consider the following 32-bit representation:
1101 1111 1100 0101 1101 1111 1100 0101 will be the number: 3754287045
If the context tells me that the above number is supposed to be a decimal at a fixed point: the 1/10,000ths spot, I
can always insert the decimal there:
375428.7045
• We can choose any fixed point in the number to represent our decimal
• However, we would need to choose this point beforehand, and it would apply to any number we
encoded
• This is called _____________representation because the decimal point is always fixed in the same place
• Fixed-point decimals are not the ideal way to represent decimals
• They are very limited in the range of values they can represent.
• In our example (with 32 bits), we could encode the numbers 0 – 429496.7295
• That seems like a fairly large range, but we couldn't even encode 1 million using this 32-bit, 4 decimal
place, fixed-point representation
• Therefore, floating point numbers are used in most modern computers
• ____________________ representation means that not only is the numeric
value determined by the binary representation, but where the decimal point
is located is encoded in binary
• Note that moving the decimal point allows us to encode a much wider
range of numbers than we could with fixed-point representation
Computing Errors
There are three different types of errors you need to be ready for when developing programs:
• A _____________ error is a mistake in the algorithm or program that causes it to behave incorrectly or
unexpectedly
• A _____________ error is a mistake in the program where the rules of the programming language are
not followed.
• A _____________error is a mistake in the program that occurs during the execution of a program.
Different programming languages have different run-time errors.
Overflow Errors
• A special type of run-time error is the _______________________
• In many programming languages, integers are represented by a _____________
__________, which limits the range of integer values it can represent
• When programs try to use numbers outside of these ranges, an overflow error
occurs
• Computers store numbers in memory based on if they are an integer or decimal.
• When the number is a decimal, and floating-point representation is used, it can
fall short at representing infinitely repeating decimals, since we cannot store an infinite sequence in a
computer
• At some point, the computer has to end the number, and it does this by either truncating or rounding
Because of this, you might see some interesting results when working with floating point numbers. Take, for
example, the Python code below. What would you expect and what is actually printed?
print(0.1 + 0.1 + 0.1)
• You would expect the answer: _________
• What you will actually get printed to the screen is: _____________________________
This is because each value of 0.1 is stored as a rounded-off binary number and when mathematical operations
are performed on a rounded off value, you might get some errors.