In: Computer Science
2. a) Represent the decimal value 47.375 as a single precision IEEE floating point number. Give your answer in hexadecimal and show your work.
b) Represent the decimal value 47.375 as a double precision IEEE floating point number. Give your answer in hexadecimal and show your work.

a)
47.375
Converting 47.375 to binary
Convert decimal part first, then the fractional part
> First convert 47 to binary
Divide 47 successively by 2 until the quotient is 0
> 47/2 = 23, remainder is 1
> 23/2 = 11, remainder is 1
> 11/2 = 5, remainder is 1
> 5/2 = 2, remainder is 1
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 101111
So, 47 of decimal is 101111 in binary
> Now, Convert 0.37500000 to binary
> Multiply 0.37500000 with 2. Since 0.75000000 is < 1. then add 0 to result
> Multiply 0.75000000 with 2. Since 1.50000000 is >= 1. then add 1 to result
> Multiply 0.50000000 with 2. Since 1.00000000 is >= 1. then add 1 to result
> This is equal to 1, so, stop calculating
0.375 of decimal is .011 in binary
so, 47.375 in binary is 00101111.011
47.375 in simple binary => 101111.011
so, 47.375 in normal binary is 101111.011 => 1.01111011 * 2^5
single precision:
--------------------
sign bit is 0(+ve)
exponent bits are (127+5=132) => 10000100
Divide 132 successively by 2 until the quotient is 0
> 132/2 = 66, remainder is 0
> 66/2 = 33, remainder is 0
> 33/2 = 16, remainder is 1
> 16/2 = 8, remainder is 0
> 8/2 = 4, remainder is 0
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10000100
So, 132 of decimal is 10000100 in binary
frac/significant bits are 01111011000000000000000
so, 47.375 in single-precision format is 0 10000100 01111011000000000000000
Hexadecimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Use this table to convert from binary to hexadecimal
Converting 01000010001111011000000000000000 to hexadecimal
0100 => 4
0010 => 2
0011 => 3
1101 => D
1000 => 8
0000 => 0
0000 => 0
0000 => 0
So, in hexadecimal 01000010001111011000000000000000 is 0x423D8000
in hexadecimal it is 0x423D8000
b)
47.375
Converting 47.375 to binary
Convert decimal part first, then the fractional part
> First convert 47 to binary
Divide 47 successively by 2 until the quotient is 0
> 47/2 = 23, remainder is 1
> 23/2 = 11, remainder is 1
> 11/2 = 5, remainder is 1
> 5/2 = 2, remainder is 1
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 101111
So, 47 of decimal is 101111 in binary
> Now, Convert 0.37500000 to binary
> Multiply 0.37500000 with 2. Since 0.75000000 is < 1. then add 0 to result
> Multiply 0.75000000 with 2. Since 1.50000000 is >= 1. then add 1 to result
> Multiply 0.50000000 with 2. Since 1.00000000 is >= 1. then add 1 to result
> This is equal to 1, so, stop calculating
0.375 of decimal is .011 in binary
so, 47.375 in binary is 00101111.011
47.375 in simple binary => 101111.011
so, 47.375 in normal binary is 101111.011 => 1.01111011 * 2^5
64-bit format:
--------------------
sign bit is 0(+ve)
exponent bits are (1023+5=1028) => 10000000100
Divide 1028 successively by 2 until the quotient is 0
> 1028/2 = 514, remainder is 0
> 514/2 = 257, remainder is 0
> 257/2 = 128, remainder is 1
> 128/2 = 64, remainder is 0
> 64/2 = 32, remainder is 0
> 32/2 = 16, remainder is 0
> 16/2 = 8, remainder is 0
> 8/2 = 4, remainder is 0
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10000000100
So, 1028 of decimal is 10000000100 in binary
frac/significant bits are 0111101100000000000000000000000000000000000000000000
so, 47.375 in 64-bit format is 0 10000000100 0111101100000000000000000000000000000000000000000000
Hexadecimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Use this table to convert from binary to hexadecimal
Converting 0100000001000111101100000000000000000000000000000000000000000000 to hexadecimal
0100 => 4
0000 => 0
0100 => 4
0111 => 7
1011 => B
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
0000 => 0
So, in hexadecimal 0100000001000111101100000000000000000000000000000000000000000000 is 0x4047B00000000000
in hexadecimal it is 0x4047B00000000000
