Practice floating point problems Format for toy computer: 8 bit storage: S - 1 bit - sign: 0 for positive, 1 for negative (bit 7) E - 4 bits - bias 3 (AKA "excess 3") (bits 6 - 3) m - 3 bits, implied 1 (bits 2 - 0) 7 6 5 4 3 2 1 0 |------|-------------------|---------------| | S | exponent | mantissa | |------|-------------------|---------------| ****************************************************************************** (1) What number does the pattern 1100 1100 (AKA 0xCC) represent? S = 1 --> - exponent = 1001 = 9 9 - 3 = 6 ---> 6 mantissa = 100 fraction = .1100 So the base two number being represented is: - 0.1100 * 2 ^ 6 = - 110000 = - (1*2^5 + 1*2^4) = -(32+16) = - 48 ****************************************************************************** (2) What number does the pattern 0000 1001 (aka 0x09) S = 0 --> + exponent = 0001 = 1 1 - 3 = -2 mantissa = 001 fraction = .1001 So, the base two number being represented is: + 0.1001 * 2^(-2) Convert to base 10: 0.1001 * 2^(-2) = 1001 * 2^(-6) = 9 * 1/(2^6) = 9/64 = 0.0.140625 ****************************************************************************** (3) What is the representation of 1 1/3 = 1.33.. Only 4 bits worth of fraction can be stored: (1.3333)b10 ~= (1.0101011)b2 ~= (1.010)b2 Normalize: 1.010 = 0.1010 * 2^(1) Sign = + ==> 0 exponent = 1; add bias 1 + 3 --> 4 fraction = .1010 --> mantissa = 010 Pattern: 0 0100 010 ******************************************************************************* (4) What is actually begin represented by 0010 0010? (i.e., the answer to (3) ) S = 0 --> + exp = 0100 = 4; remove bias 4 - 3 = 1. mantissa = 010; Fraction = .1010 The base two number is + .1010 * 2^1 = (1*2^(-1)+ 1*2^(-3)) *2^1 = (1*2^0) + 1*2^(-2) = 1 + .25 = 1.25