1And in Summary¶
We represent “things” in computers as particular bit patterns:
With bits, you can represent at most things.
Today, we discussed five different encodings for integers:
Unsigned integers
Signed integers:
Sign-Magnitude
Ones’ Complement
Two’s Complement
Bias Encoding
Computer architects make design decisions to make HW simple
Unsigned and Two’s complement are C standard. Learn them!!
Integer overflow: The result of an arithmetic operation is outside the representable range of integers.
Numbers have infinite digits, but computers have finite precision. This can lead to arithmetic errors. More later!
Meta takeaway: We make design decisions to make the hardware simple. We threw out sign magnitude and ones’ complement because the hardware would be hard. But here’s a secret: it’s the same hardware for mathematics on unsigned and two’s complement numbers. The only difference is how you calculate overflow.
2Textbook Readings¶
P&H: 2.4
3Additional References¶
Dan Garcia’s Binary Slides, Fall 2025
Amazing Illustrations by Ketrina (Yim) Thompson: CS Illustrated Number Rep Handouts
4Exercises¶
Check your knowledge!
4.1Conceptual Review¶
What is a bit? How many bits are in a byte? Nibble?
Solution
A bit is the smallest unit of digital information and it can be either 0 of 1. There are 4 bits in a nibble and 8 bits in a byte.
What is overflow?
Solution
When the result of an arithmetic operation is outside the range of what is representable by given number of bits.
What is the range of numbers representable by -bit unsigned, sign-magnitude, one’s complement, two’s complement, and biased notation?
Solution
Unsigned:
Sign-Magnitude:
One’s complement:
Two’s complement:
Bias: biasbias
How many ways to represent zero do these representations have, -bit unsigned, sign-magnitude, one’s complement, two’s complement, and biased notation?
Solution
Unsigned: 1
Sign-Magnitude: 2
One’s complement: 2
Two’s complement: 1
Bias: 1 or 0 (depending on bias)
4.2Short Exercises¶
True/False: Depending on the context, the same sequence of bits may represent different things.
Solution
True. The same bits can be interpreted in many different ways with the exact same bits! The bits can represent anything from an unsigned number to a signed number or even, as we will cover later, a program. It is all dependent on its agreed upon interpretation.
True/False: If you interpret a -bit Two’s complement number as an unsigned number, negative numbers would be smaller than positive numbers.
Solution
False. In Two’s Complement, the MSB is always 1 for a negative number. This means EVERY negative number in Two’s Complement, when converted to unsigned, will be larger than the positive numbers.
True/False: We can represent fractions and decimals in our given number representation formats (unsigned, biased, and Two’s Complement).
Solution
False. Our current representation formats has a major limitation; we can only represent and do arithmetic with integers. To successfully represent fractional values as well as numbers with extremely high magnitude beyond our current boundaries, we need another representation format.
How many numbers can be represented by an unsigned, base-4, -digit number.
A. 1
B.
C.
D.
E.
Solution
C.
How many bits are needed to represent decimal number 116 in binary?
Solution
7 bits. 0b111 0100 or which we round to 7 bits.