1
votes

Can someone help me with this question:

“Convert the decimal number 10/32 to the 32-bit IEEE 754 floating point and express your answer in hexadecimal. (Reminder: the 32 bits are used as follows: Bit 1: sign of mantissa, bits 2-9: 8-bits of exponent in excess 127, bits 10-32: 23 bits for magnitude of mantissa.)”

I understand how to convert a decimal number to IEE 754. But I am confused on how to answer this—it only gives me a quotient? I am not allowed to use a calculator, so I am unsure how to work this out. Should I convert them both to binary first and divide them?

3
I removed “equation” from the title because “10/32” is not an equation. An equation has an equal sign and is a statement that two things have the same value. “10/32” is merely an expression or a rational number. I left the incorrect “decimal number” because it is inside quotes, so presumably it comes from another source. That source is wrong; “10/32” is not a decimal number. It is an expression that uses two decimal numerals, and it may be considered a rational number due to the definition of rational numbers as the ratios of integers.Eric Postpischil

3 Answers

0
votes

I see it like this:

10/32 =        // input
10/2^5 =       // convert division by power of 2 to bitshift
1010b >> 5 =
.01010b        // fractional result
--^-------------------------------------------------------------
  |
first nonzero bit is the exponent position and start of mantissa
----------------------------------------------------------------
man = (1)010b           // first one is implicit
exp = -2 + 127 = 125    // position from decimal point + bias
sign = 0                // non negative
----------------------------------------------------------------
0 01111101 01000000000000000000000 b
^    ^                ^
|    |            mantissa + zero padding
|   exp
sign
----------------------------------------------------------------
0011 1110 1010 0000 0000 0000 0000 0000 b
   3    E    A    0    0    0    0    0 h
----------------------------------------------------------------
3EA00000h

Yes the answer of Eric Postpischil is the same approach (+1 btw) but I didn't like the formating as it was not clear from a first look what to do without proper reading the text.

1
votes

10/32 = 5/16 = 5•2−4 = 1.25•2−2 = 1.012•2−2.

The sign is +, the exponent is −2, and the significand is 1.012.

A positive sign is encoded as 0.

Exponent −2 is encoded as −2 + 127 = 125 = 011111012.

Significand 1.012 is 1.010000000000000000000002, and it is encoded using the last 23 bits, 010000000000000000000002.

Putting these together, the IEEE-754 encoding is 0 01111101 01000000000000000000000. To convert to hexadecimal, first organize into groups of four bits: 0011 1110 1010 0000 0000 0000 0000 0000. Then the hexadecimal can be easily read: 3EA0000016.

0
votes

Giving the conversion of 10/322 without a calculator as an exercise is pure sadism.

There is a a general method doable without tools, but it may be tedious.

N is the number to code. We assume n<1
exp=0
mantissa=0 
repeat 
  n *= 2
  exp ++
  if n>1
    n = n-1
    mantissa = mantissa <<1 | 1
  else
    mantissa = mantissa <<1
until mantissa is a 1 followed by 23 bits

Then you just have to code mantissa and (23-exp) in IEEE format.

Note that frequently this kind of computations lead to loops. Whenever you find the same n, you know that the sequence will be repeated.

As an example, assume we have to code 3/14

3/14  -> 6/14  e=1 m=0  
6/14  -> 12/14 e=2 m=00
12/14 -> 24/14-14/14=10/14 e=3 m=001
10->14 -> 20/14-14/14=6/14 e=4 m=0011
6/14   -> 12/14 e=5 m=00110

Great we found a loop !
6/14->12/14->10/14->6/14.
So the mantissa will be 110 iterated as required 110110110...

If we fill the mantissa with 24 bits, we need 26 iterations and exponent is 23-26=-3 (another way to get it is to remark that n became >1 for the first time at iteration 3 and exponent is -3 as 1≤3/14*2^3<2).

And we can do the IEEE754 coding with exponent=127-3=124 and mantissa =1.1011011011011....