CMPT 295: Unit - Data Representation

Lecture 5

Last Lecture

Conclusion: the same bit pattern is interpreted differently.

Questions

Demo – Looking at integer additions in C

Today’s Menu

We’ll illustrate what we covered today by having a demo!

Converting a fractional decimal number into a binary number (bit vector) [R2B(X)]

Starting number: 346.625

Whole:

Value Attempted Addition (subtraction) value Result Binary Implication Note
346 -256 90 1×281 \times 2^{8} MSb
90 -128 0×270 \times 2^{7}  
90 -64 26 1×261 \times 2^{6}  
26 -32 0×250 \times 2^{5}  
26 -16 10 1×241 \times 2^{4}  
10 -8 2 1×231 \times 2^{3}  
2 -4 0×220 \times 2^{2}  
2 -2 0 1×211 \times 2^{1}  
0 -1 0×210 \times 2^{1} LSb

Fractional:

Value Attempted addition (subtraction) value result binary implication notes
.625 -0.5 .125 1×211 \times 2^{-1} MSb
.125 -0.25 0×220 \times 2^{-2}  
.125 -0.125 0 1×231 \times 2^{-3} LSb

Binary representation is: 101011010.1012\text{101011010.101}_{2}

First, last binary digit before the period are MSb, LSb respectively. First, last binary digit after the period are also MSb, LSb respectively.

Negative Powers of 2:

Converting a binary number into a fractional decimal number [R2B(X)]

Review: Fractional decimal numbers

Positional notation:

Notation Value
did_{i} 10i\text{10}^{i}
di1d_{i-1} 10i1\text{10}^{i-1}
d2d_{2} 100
d1d_{1} 10
d0d_{0} 1
d1d_{-1} 110\frac{1}{10}
d2d_{-2} 1100\frac{1}{100}
d3d_{-3} 11000\frac{1}{1000}
djd_{-j} 10j\text{10}^{-j}

Example: 2.345

Digit in number Note
2 100\text{10}^{0}
.  
3 101\text{10}^{-1}
4 102\text{10}^{-2}
5 103\text{10}^{-3}

2.345=2×100+3×101+4×102+5×103 2.345 = 2 \times \text{10}^{0} + 3 \times \text{10}^{−1} + 4 \times \text{10}^{−2} + 5 \times \text{10}^{−3}

Converting a binary number into a fractional decimal number [B2R(X)]

Positional notation: can this be a possible encoding scheme?

bib_{i} 2i2^{i}
bi1b_{i-1} 2i12^{i-1}
b2b_{2} 4
b1b_{1} 2
b0b_{0} 1
b1b_{-1} 12\frac{1}{2}
b2b_{-2} 14\frac{1}{4}
b3b_{-3} 18\frac{1}{8}
bjb_{-j} 2j2^{-j}

Converting a binary number into a fractional decimal number [B2R(X)]

1011.1012=(10112=1×23+1×21+1×20=1110)+(.1012=1×21+1×23=0.5+0.125=0.62510) \begin{aligned} &\text{1011.101}_{2} = \\ &(\text{1011}_{2} = 1 \times 2^{3} + 1 \times 2^{1} + 1 \times 2^{0} = \text{11}_{10}) +\\ &(\text{.101}_{2} = 1 \times 2^{-1} + 1 \times 2^{-3} = 0.5 + 0.125 = \text{0.625}_{10}) \end{aligned}

Result: ____

Negative Powers of 2

212^{−1} 0.5
222^{−2} 0.25
232^{−3} 0.125
242^{−4} 0.0625
252^{−5} 0.03125
262^{−6} 0.015625
272^{−7} 0.0078125
282^{−8} 0.00390625

Positional notation as encoding scheme?

Example:

Operand Binary Fraction Makeup
  1011.1012\text{1011.101}_{2} 115811\frac{5}{8} 8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Divide by 2 101.11012\text{101.1101}_{2} 513165\frac{13}{16} 4+1+12+14+1164 + 1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{16}
Divide by 2 10.111012\text{10.11101}_{2} 229322\frac{29}{32} 2+12+14+18+1322 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{32}
Multiply by 4 1011.1012\text{1011.101}_{2} 115811\frac{5}{8} 8+2+1+12+188 + 2 + 1 + \frac{1}{2} + \frac{1}{8}
Multiply by 2 10111.012\text{10111.01}_{2} 231423\frac{1}{4} 16+4+2+1+1416 + 4 + 2 + 1 + \frac{1}{4}

So far so good!

Positional notation as encoding scheme?

Not so good anymore!

Representing fractional numbers in memory

IEEE Floating Point Representation – Precision options

IEEE Floating Point Representation – Three “kinds” of values

Numerical Form: V=(–1)sM2EV = \text{(–1)}^{s} M 2^{E}

Why is E biased? Using single precision as an example:

Why adding 1 to frac? Because number V is first normalized before it is converted.

Review: Scientific Notation and normalization

Syntax:

Notation Name
+/− sign
d0d_{0}, d1d_{-1}, d2d_{-2}, d3d_{-3}dnd_{-n} significand
× times
b base
exp^{exp} exponent

Let’s try: 101011010.1012\text{101011010.101}_{2} = ____

Summary

Today’s Menu