Week 4 - Tute Slides Week 4
Week 4 - Tute Slides Week 4
Tutorial 2
Encoding, Binary and Fixed Point
EX
Addition/Subtraction with two's complement
T
1010
-8 4 2 1
1 0 1 0
-8 0 2 0
=-6
Review: Two’s Complement
How do we represent a negative number in binary?
MSB is Sign Bit
1010
1 = Negative Number
0 = Positive Number
-8 4 2 1
1 0 1 0
-8 0 2 0
=-6
Review: Decimal to Binary
Review: Decimal to Binary
From last week: Two methods! (for negative numbers)
-1810
Review: Decimal to Binary
From last week: Two methods! (for negative numbers)
-1810
1. Express absolute value of the number in unsigned binary
32 16 8 4 2 1
0 1 0 0 1 0
Review: Decimal to Binary
From last week: Two methods! (for negative
numbers)
-1810
1. Express absolute value of the number in unsigned binary
32 16 8 4 2 1
0 1 0 0 1 0
2. Invert bits
010010 101101
Review: Decimal to Binary
-1810
1. Express absolute value of the number in unsigned binary
32 16 8 4 2 1
0 1 0 0 1 0
2. Invert bits
010010 101101
3. Add one Carry 0 0 0 0 1 -
Origina 1 0 1 1 0 1
l
+1 0 0 0 0 0 1
Result 1 0 1 1 1 0
Review: Decimal to Binary
-1810
Let’s verify the result!
-32 16 8 4 2 1
1 0 1 1 1 0
= -32 + 8 + 4 + 2
= -32 + 14
= -18 😄
Review: Decimal to Binary
From last week: Two methods! (for negative numbers)
-1810
The other method…
-32 16 8 4 2 1
0 0 1 1 1 0
-1810
The other method…
-32 16 8 4 2 1
0 0 1 1 1 0
😃
Two’s Complement with Fixed Point
We use the same methods, but now including a fixed number of
bits for our fractional component
-5.7510
e.g.
Two’s Complement with Fixed Point
We use the same methods, but now including a fixed number of
bits for our fractional component
e.g.
-5.7510
1. Express absolute value of the number in unsigned binary
010111 101000
Two’s Complement with Fixed Point
We use the same methods , but now including a fixed number of
bits for our fractional component
-5.7510
1. Express absolute value of the number in unsigned binary
0101.11 1010.00
3. Add 1 (in our least significant bit)
-8 4 2 1 0.5 0.25
1 0 1 0 0 1
= -8 + 2 + 0.25
= -8 + 2.25
= -5.75 😄
Binary to Hexadecimal
Recall from last week: Hexadecimal = Base 16
Binary to Hexadecimal
Recall from last week: Hexadecimal = Base 16
e.g. 0010101010001011
Binary to Hexadecimal
For any integer binary number, we can change it to hex by grouping bits
right to left in groups of four, then using our table.
(Reminder)
e.g. 0010101010001011 Binary Hexadecim
al
1000 8
0010 1010 1000 1011 1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
Binary to Hexadecimal
For any integer binary number, we can change it to hex by grouping bits
right to left in groups of four, then using our table.
(Reminder)
e.g. 0010101010001011 Binary Hexadecim
al
1000 8
0010 1010 1000 1011 1001 9
2 A 8 B 1010
1011
A
B
1100 C
1101 D
=2A8B16 1110 E
1111 F
Binary to Hexadecimal
For any integer binary number, we can change it to hex by grouping bits
right to left in groups of four, then using our table. (Reminder)
Binary Hexadecim
e.g. 0010101010001011 al
1000 8
(b)1010.1011 (b)12.25
Activity 1 Q2. Convert the following
Q1. Convert the following decimal numbers to (i)
fixed-point numbers to fixed-point binary and (ii)
decimal: fixed-point hexadecimal
(a)1101.011 Pad bits to a
(a) 7.510 multiple of four
for our
= (i) 0111.1000 2conversion
= 13.375 (ii) =7.816
(b) 1010.1011
(b)12.2510
= 10.6875 (i) 1100.01002
(ii) =C.4
Choosing the number of bits
• When we choose the number of bits to use in our number system, it
impacts the range of numbers we can represent.
• More bits allow for more precise fractional values (higher precision) or a
larger range of numbers.
• More bits allow for more precise fractional values (higher precision) or
larger/smaller numbers (larger range).
• More bits allow for more precise fractional values (higher precision) or
larger/smaller numbers (larger range).
(ii) You must choose a single number Note: 0x is the prefix for
system. What is your chosen number hexadecimal, like how we use 10
system? subscript to represent base 10
i.e. 7 - 5 = 7 + (-5)
Activity 3 (EXT): Solutions
Scaling and bias (Extension)
For some unsigned integer with k bits, we can represent
Bias
Scaling
Constant shift of each number in
Scalar multiple of each number in
range . i.e. we can represent
range. i.e. we can represent
where b is the bias.
Errors in Representation(Extension)
How can we find the maximum error in a representation?
Errors in Representation(Extension)
How can we find the maximum error in a representation?
1 1.5 2 3
This will be halfway between two numbers we can represent so half the
smallest power of two in our representation.
Quiz!