Comp 222: Binary Systems - Study Notes
My Study Insights
As a Comp 222 student, understanding binary systems is foundational. This isnt just
math; it’s the language of the machine. Everything from simple data storage to
complex instructions is encoded in
0
s and
1
s. My key insight is this: Focus on the
methods, not just the answers. The process of conversion, especially between
binary, decimal, and hexadecimal, will be critical for understanding how memory
addresses and assembly instructions work later in the course.
The concepts of 2s Complement and signed vs. unsigned representation are often
tricky. Take your time to grasp why
2
s complement is used (it simplifies subtraction
into addition for the CPU) and how the most significant bit (MSB) determines the
sign.
I. Core Knowledge Points Summary
1. Number Systems
System
Base
(Radix) Digits Used
Weight/Position
Value
Application in
Computing
Decimal 10
0,1, … ,9
10i
Human-readable
input/output.
Binary 2
0,1
2i
The native
language of all
digital computers
(the ON/OFF state
of a transistor).
Octal 8
0,1, … ,7
8i
Rarely used
today; historically
used as a compact
form of binary.
Hexadecimal
(Hex)
16
0,1, … ,9, A , B , C , D , E , F
16i
The standard
compact form of
binary
representation for
memory
addresses and
data (e.g.,
4
bits
¿1
Hex digit).
2. General Positional Notation
Any number
N
in base
r
can be expressed as:
Nr=¿
Where
di
is a digit and
r
is the base.
The decimal value is calculated by:
DecimalValue=∑
i=− m
n −1
di⋅ri
3. Conversions
Decimal to Other Bases (e.g., Decimal to Binary):
oInteger Part: Use the Repeated Division by
r
method. The
remainders, read from bottom to top, form the new base number.
oFractional Part: Use the Repeated Multiplication by
r
method. The
integer parts, read from top to bottom, form the fractional part of the
new base number.
Other Bases to Decimal (e.g., Binary to Decimal):
oUse the Positional Notation formula (sum of
di⋅ri
).
Binary
↔
Hexadecimal:
oBinary to Hex: Group binary bits into sets of four, starting from the
radix point. Convert each group to its corresponding Hex digit.
oHex to Binary: Convert each Hex digit into its corresponding four-bit
binary representation.
4. Signed Integer Representation
To represent negative numbers, we use the Most Significant Bit (MSB) as the sign
bit.
Method Description
Range (for
n
bits)
Sign-Magnitude MSB =
0
(Positive), MSB =
1
(Negative). The
remaining
n −1
bits hold the magnitude.
−(2n −1−1)
to
(2n −1−1)
1s Complement Negative number is formed by inverting all
bits of the positive number.
−(2n −1−1)
to
(2n −1−1)
2s Complement
(Most Common)
Negative number is formed by taking the
1
s
complement and adding
1
.
−2n− 1
to
(2n −1−1)
Why 2s Complement? It has only one representation for
0
(all
0
s) and
allows subtraction to be performed using standard binary addition, which
simplifies CPU hardware.
5. Binary Arithmetic
Addition (Unsigned): Follows basic rules:
o
0+0=0
o
0+1=1
o
1+0=1
o
1+1=0
(Carry
1
)
Subtraction (2s Complement): To calculate
A − B
:
a. Find the 2s Complement of
B
(i.e.,
− B
).
b. Perform the addition:
A+(− B)
.
c. Ignore any final carry out (it represents the discarded sign bit).
Overflow: Occurs when the result of an addition/subtraction exceeds the
range of the
n
-bit representation.
oRule: Overflow occurs if:
i. Adding two positive numbers yields a negative result.
ii. Adding two negative numbers yields a positive result.
iii. Adding a positive and a negative number never results in an
overflow.
II. Solved Examples📝
Example 1: Base Conversion (Binary to Decimal/Hex)
Problem: Convert the binary number
110110.0112
to its decimal and hexadecimal
equivalents.
A. Binary to Decimal:
110110.0112=1⋅25+1⋅24+0⋅23+1⋅22+1⋅21+0⋅20+0⋅2−1+1⋅2−2+1⋅2−3=32+16+0+4+2+0+0+0.25+0.125=54.37510
B. Binary to Hexadecimal:
1. Group by four bits from the radix point:
0011
¿0110
¿⋅0110
¿
(We added leading
00
to the integer part and trailing
0
to the fractional part
to complete the groups of four.)
2. Convert each group:
36.616
Example 2: Decimal to Binary (Integers)
Problem: Convert the decimal number
12310
to an 8-bit binary number.
Method: Repeated Division by 2
Division Quotient Remainder (Binary Digit)
123 ÷2
61
1
(LSB)
61 ÷2
30
1
30 ÷2
15
0
15 ÷2
7
1
7÷2
3
1
3÷2
1
1
1÷2
0
1
(MSB)
Reading the remainders from bottom to top:
11110112
.
As an 8-bit number, we add a leading zero:
011110112
.
Example 3: 2s Complement Representation
Problem: Represent the decimal numbers
+1310
and
−1310
using 8-bit 2s
Complement representation.
A. Representing
+1310
:
1. Convert the magnitude
13
to binary:
11012
.
2. Pad to 8 bits with leading zeros (MSB is
0
for positive):
000011012
B. Representing
−1310
:
3. Start with
+13
:
000011012
4. Step 1: Find 1s Complement (Invert all bits):
11110010
5. Step 2: Add
1
to the 1s Complement:
11110010+1=111100112
Example 4: 2s Complement Binary Subtraction
Problem: Using 8-bit 2s Complement arithmetic, calculate
2510 −1310
.
This is equivalent to
2510 +(−1310)
.
1. Represent
2510
in 8-bit binary:
2510=000110012
2. Represent
−1310
in 8-bit 2s Complement (from Example 3):
−1310=111100112
3. Perform Binary Addition:
11111100 ←Carries
00011001 (25)
+¿11110011 (−13)
(1)¿
(12)¿
4. Result Analysis:
oThe
9th
bit (the carry out) is ignored in 2s Complement arithmetic.
oThe 8-bit result is
000011002
.
o
000011002=8+4=1210
. This is the correct result.
Example 5: Detecting Overflow
Problem: Using 4-bit 2s Complement, perform the additions and determine if an
overflow occurs. (Range is
−8
to
+7
).
A.
5+4
5=01012
4=01002
0100 ←Carries
0101 (+5)
+¿0100 (+4)
1001 (−7)
Result is
10012
. The result of adding two positive numbers (
0101
and
0100
) yielded
a negative result (MSB is
1
).
OVERFLOWoccurred.(5+4=9,which is outside the range of+7).
B.
(−5)+(−4)
−5=10112
(2s complement of
0101
)
−4=11002
(2s complement of
0100
)
1100 ←Carries
1011 (−5)
+¿1100 (−4)
(1)¿
(+7)¿
Result is
01112
. The result of adding two negative numbers (
1011
and
1100
) yielded
a positive result (MSB is
0
).
OVERFLOWoccurred. (−5+−4=−9,which is outside the range of−8).