0% found this document useful (0 votes)
4 views49 pages

Week 4 - Tute Slides Week 4

This document covers concepts related to fixed-point numbers, binary representation, and two's complement. It includes methods for converting between decimal, binary, and hexadecimal systems, as well as discussions on the implications of choosing the number of bits for representation. Additionally, it touches on errors in representation and the use of scaling and bias for managing ranges in limited bit systems.

Uploaded by

Yuchen Chen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views49 pages

Week 4 - Tute Slides Week 4

This document covers concepts related to fixed-point numbers, binary representation, and two's complement. It includes methods for converting between decimal, binary, and hexadecimal systems, as well as discussions on the implications of choosing the number of bits for representation. Additionally, it touches on errors in representation and the use of scaling and bias for managing ranges in limited bit systems.

Uploaded by

Yuchen Chen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

ELEC1601

Tutorial 2
Encoding, Binary and Fixed Point

* Not official course material


Today’s Agenda:

Fixed-point numbers review

Choosing the number of bits

EX
Addition/Subtraction with two's complement
T

Quiz! (30 mins)


Review: Two’s Complement
How do we represent a negative number in binary?
Review: Two’s Complement
How do we represent a negative number in binary?

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

Use our normal algorithm with a negative MSB 🙂


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

Use our normal algorithm with a negative MSB 🙂

+ Remember, the binary representation of a positive number in two's


complement is simply the same as its unsigned binary form.
Review: Fixed point
How can we represent the fractional part of numbers e.g. 0.625 in our
number systems?
Review: Fixed point
How can we represent the fractional part of numbers e.g. 0.625 in our
number systems?
Quick Example: Fixed point
5.7510=

😃
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

8 4 2 1 0.5 (1/2) 0.25


5.7510 = (1/4)
0 1 0 1 1 1
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

8 4 2 1 0.5 (1/2) 0.25


5.7510 = (1/4)
0 1 0 1 1 1
2. Invert bits

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

8 4 2 1 0.5 (1/2) 0.25


5.7510 = (1/4)
0 1 0 1 1 1
2. Invert bits

0101.11  1010.00
3. Add 1 (in our least significant bit)

1010.00 + 0000.01 = 1010.01


Two’s Complement with Fixed Point
-5.7510
Let’s verify the result!

-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

How can we have 16 different ‘digits’?


Binary to Hexadecimal
Recall from last week: Hexadecimal = Base 16

How can we have 16 different ‘digits’?


Decimal Hexadecim Decimal Hexadecim
al al
0 0 8 8
1 1 9 9
2 2 10 A
3 3 11 B
4 4 12 C
5 5 13 D
6 6 14 E
Binary to Hexadecimal
Recall from last week: Hexadecimal = Base 16

How can we have 16 different ‘digits’?


Decimal Hexadecim Decimal Hexadecim
al al
0 0 8 8
1 1 9 9
2 2 10 A
3 3 11 B
After 10, we
4 4 12 C switch to
5 5 13 D letters A-F!
6 6 14 E
Binary to Hexadecimal
How can we convert between hex and binary, now we know the base
10 equivalent?

Decimal Hexadecim Decimal Hexadecim


al al
0 0 8 8
1 1 9 9
2 2 10 A
3 3 11 B
4 4 12 C
5 5 13 D
6 6 14 E
Binary to Hexadecimal
How can we convert between hex and binary, now we know the base
10 equivalent?

Let’s add the binary equivalent of each digit to our table…


Decimal Binary Hexadecim Decimal Binary Hexadecim
al al
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
Binary to Hexadecimal
For any binary number, we can change it to hex by grouping bits right to
left in groups of four, then using our table.
Binary to Hexadecimal
For any binary number, we can change it to hex by grouping bits right to
left in groups of four, then using our table.

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

0010 1010 1000 1011 1001 9


1010 A
2 A 8 B 1011 B
1100 C
1101 D
=2A8B16 1110 E
1111 F
Note for hex to binary, we do the
For fractional bits, we form groups of 4
opposite: expand each digit back into a bits left to right instead.
Activity 1 Q2. Convert the following
decimal numbers to (i)
Q1. Convert the following
fixed-point binary and (ii)
fixed-point numbers to
fixed-point hexadecimal
decimal:

(a)1101.011 (a) 7.5

(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.

But, more bits = more memory usage.


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
larger/smaller numbers (larger range).

But, more bits = more memory usage.

e.g. 3 bits  000 (0) to 111 (7) Unsigned integer with k


e.g. 4 bits  0000 (0) to 1111 (15)
bits
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
larger/smaller numbers (larger range).

But, more bits = more memory usage.

e.g. 3 bits  000 (0) to 111 (7) Unsigned integer with k


e.g. 4 bits  0000 (0) to 1111 (15)
bits

e.g. 3 bits  100 (-4) to 011 (3) 2’s complement with k


bits
e.g. 4 bits  1000 (-8) to 0111 (7)
Activity 2: Solutions
(i) How many bits are required to (iii) For your final number representation, translate each
represent each number? number to hexadecimal.

10110 0110 0101  0x65


5510 0011 0111  0x37
2710 0001 1011  0x1B
110 0000 0001  0x01

(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 

We will choose unsigned binary to represent


these because all the digits are positive. Since
all values must have the same number of bits
in the array we can use 8 bits per number.
We prefer to choose multiples of 8 (why?)
Addition and Subtraction with 2’s
Complement (Review, Extension)
Recall from last week:

Subtraction with binary numbers can be rephrased as addition with a


negative (using 2’s complement).

i.e. 7 - 5 = 7 + (-5)
Activity 3 (EXT): Solutions
Scaling and bias (Extension)
For some unsigned integer with k bits, we can represent

Sometimes, we are restricted for bits but want to represent a different


range.
Scaling and bias (Extension)
For some unsigned integer with k bits, we can represent

Sometimes, we are restricted for bits but want to represent a different


range.

This is when scaling and bias become useful!

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?

Idea  how do we choose a number so that it is furthest away from the


numbers we can represent?
Errors in Representation(Extension)
How can we find the maximum error in a representation?

Idea  how do we choose a number so that it is furthest away from the


numbers we can represent?

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!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy