In: Computer Science
convert -47.199 to IEEE-754 single precision and double
precision both.
Need a lot of explanation. (Atleast 1000 words)
1)
-47.199
Converting 47.199 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.19900000 to binary
> Multiply 0.19900000 with 2.
Since 0.39800000 is < 1. then add 0 to result
> Multiply 0.39800000 with 2.
Since 0.79600000 is < 1. then add 0 to result
> Multiply 0.79600000 with 2.
Since 1.59200000 is >= 1. then add 1 to
result
> Multiply 0.59200000 with 2.
Since 1.18400000 is >= 1. then add 1 to
result
> Multiply 0.18400000 with 2.
Since 0.36800000 is < 1. then add 0 to result
> Multiply 0.36800000 with 2.
Since 0.73600000 is < 1. then add 0 to result
> Multiply 0.73600000 with 2.
Since 1.47200000 is >= 1. then add 1 to
result
> Multiply 0.47200000 with 2.
Since 0.94400000 is < 1. then add 0 to result
> Multiply 0.94400000 with 2.
Since 1.88800000 is >= 1. then add 1 to
result
> Multiply 0.88800000 with 2.
Since 1.77600000 is >= 1. then add 1 to
result
> Multiply 0.77600000 with 2.
Since 1.55200000 is >= 1. then add 1 to
result
> Multiply 0.55200000 with 2.
Since 1.10400000 is >= 1. then add 1 to
result
> Multiply 0.10400000 with 2.
Since 0.20800000 is < 1. then add 0 to result
> Multiply 0.20800000 with 2.
Since 0.41600000 is < 1. then add 0 to result
> Multiply 0.41600000 with 2.
Since 0.83200000 is < 1. then add 0 to result
> Multiply 0.83200000 with 2.
Since 1.66400000 is >= 1. then add 1 to
result
> Multiply 0.66400000 with 2.
Since 1.32800000 is >= 1. then add 1 to
result
> Multiply 0.32800000 with 2.
Since 0.65600000 is < 1. then add 0 to result
> Multiply 0.65600000 with 2.
Since 1.31200000 is >= 1. then add 1 to
result
> Multiply 0.31200000 with 2.
Since 0.62400000 is < 1. then add 0 to result
> Multiply 0.62400000 with 2.
Since 1.24800000 is >= 1. then add 1 to
result
> Multiply 0.24800000 with 2.
Since 0.49599999 is < 1. then add 0 to result
> Multiply 0.49599999 with 2.
Since 0.99199998 is < 1. then add 0 to result
> Multiply 0.99199998 with 2.
Since 1.98399997 is >= 1. then add 1 to
result
> Multiply 0.98399997 with 2.
Since 1.96799994 is >= 1. then add 1 to
result
> Multiply 0.96799994 with 2.
Since 1.93599987 is >= 1. then add 1 to
result
> Multiply 0.93599987 with 2.
Since 1.87199974 is >= 1. then add 1 to
result
> Multiply 0.87199974 with 2.
Since 1.74399948 is >= 1. then add 1 to
result
> Multiply 0.74399948 with 2.
Since 1.48799896 is >= 1. then add 1 to
result
> Multiply 0.48799896 with 2.
Since 0.97599792 is < 1. then add 0 to result
> Multiply 0.97599792 with 2.
Since 1.95199585 is >= 1. then add 1 to
result
> Multiply 0.95199585 with 2.
Since 1.90399170 is >= 1. then add 1 to
result
> Multiply 0.90399170 with 2.
Since 1.80798340 is >= 1. then add 1 to
result
> Multiply 0.80798340 with 2.
Since 1.61596680 is >= 1. then add 1 to
result
> Multiply 0.61596680 with 2.
Since 1.23193359 is >= 1. then add 1 to
result
> Multiply 0.23193359 with 2.
Since 0.46386719 is < 1. then add 0 to result
> Multiply 0.46386719 with 2.
Since 0.92773438 is < 1. then add 0 to result
> Multiply 0.92773438 with 2.
Since 1.85546875 is >= 1. then add 1 to
result
> Multiply 0.85546875 with 2.
Since 1.71093750 is >= 1. then add 1 to
result
> Multiply 0.71093750 with 2.
Since 1.42187500 is >= 1. then add 1 to
result
> Multiply 0.42187500 with 2.
Since 0.84375000 is < 1. then add 0 to result
> Multiply 0.84375000 with 2.
Since 1.68750000 is >= 1. then add 1 to
result
> Multiply 0.68750000 with 2.
Since 1.37500000 is >= 1. then add 1 to
result
> 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.19899999999999807 of decimal is
.0011001011110001101010011111101111100111011011 in binary
so, 47.199 in binary is
101111.0011001011110001101010011111101111100111011011
-47.199 in simple binary =>
101111.0011001011110001101010011111101111100111011011
so, -47.199 in normal binary is
101111.0011001011110001101010011111101111100111011011 =>
1.0111100110010111100011 * 2^5
single precision:
--------------------
sign bit is 1(-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 01111001100101111000110
so, -47.199 in single-precision format is 1 10000100
01111001100101111000110
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 11000010001111001100101111000110 to hexadecimal
1100 => C
0010 => 2
0011 => 3
1100 => C
1100 => C
1011 => B
1100 => C
0110 => 6
So, in hexadecimal 11000010001111001100101111000110 is
0xC23CCBC6
in hexadecimal it is 0xC23CCBC6
2)
-47.199
Converting 47.199 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.19900000 to binary
> Multiply 0.19900000 with 2.
Since 0.39800000 is < 1. then add 0 to result
> Multiply 0.39800000 with 2.
Since 0.79600000 is < 1. then add 0 to result
> Multiply 0.79600000 with 2.
Since 1.59200000 is >= 1. then add 1 to
result
> Multiply 0.59200000 with 2.
Since 1.18400000 is >= 1. then add 1 to
result
> Multiply 0.18400000 with 2.
Since 0.36800000 is < 1. then add 0 to result
> Multiply 0.36800000 with 2.
Since 0.73600000 is < 1. then add 0 to result
> Multiply 0.73600000 with 2.
Since 1.47200000 is >= 1. then add 1 to
result
> Multiply 0.47200000 with 2.
Since 0.94400000 is < 1. then add 0 to result
> Multiply 0.94400000 with 2.
Since 1.88800000 is >= 1. then add 1 to
result
> Multiply 0.88800000 with 2.
Since 1.77600000 is >= 1. then add 1 to
result
> Multiply 0.77600000 with 2.
Since 1.55200000 is >= 1. then add 1 to
result
> Multiply 0.55200000 with 2.
Since 1.10400000 is >= 1. then add 1 to
result
> Multiply 0.10400000 with 2.
Since 0.20800000 is < 1. then add 0 to result
> Multiply 0.20800000 with 2.
Since 0.41600000 is < 1. then add 0 to result
> Multiply 0.41600000 with 2.
Since 0.83200000 is < 1. then add 0 to result
> Multiply 0.83200000 with 2.
Since 1.66400000 is >= 1. then add 1 to
result
> Multiply 0.66400000 with 2.
Since 1.32800000 is >= 1. then add 1 to
result
> Multiply 0.32800000 with 2.
Since 0.65600000 is < 1. then add 0 to result
> Multiply 0.65600000 with 2.
Since 1.31200000 is >= 1. then add 1 to
result
> Multiply 0.31200000 with 2.
Since 0.62400000 is < 1. then add 0 to result
> Multiply 0.62400000 with 2.
Since 1.24800000 is >= 1. then add 1 to
result
> Multiply 0.24800000 with 2.
Since 0.49599999 is < 1. then add 0 to result
> Multiply 0.49599999 with 2.
Since 0.99199998 is < 1. then add 0 to result
> Multiply 0.99199998 with 2.
Since 1.98399997 is >= 1. then add 1 to
result
> Multiply 0.98399997 with 2.
Since 1.96799994 is >= 1. then add 1 to
result
> Multiply 0.96799994 with 2.
Since 1.93599987 is >= 1. then add 1 to
result
> Multiply 0.93599987 with 2.
Since 1.87199974 is >= 1. then add 1 to
result
> Multiply 0.87199974 with 2.
Since 1.74399948 is >= 1. then add 1 to
result
> Multiply 0.74399948 with 2.
Since 1.48799896 is >= 1. then add 1 to
result
> Multiply 0.48799896 with 2.
Since 0.97599792 is < 1. then add 0 to result
> Multiply 0.97599792 with 2.
Since 1.95199585 is >= 1. then add 1 to
result
> Multiply 0.95199585 with 2.
Since 1.90399170 is >= 1. then add 1 to
result
> Multiply 0.90399170 with 2.
Since 1.80798340 is >= 1. then add 1 to
result
> Multiply 0.80798340 with 2.
Since 1.61596680 is >= 1. then add 1 to
result
> Multiply 0.61596680 with 2.
Since 1.23193359 is >= 1. then add 1 to
result
> Multiply 0.23193359 with 2.
Since 0.46386719 is < 1. then add 0 to result
> Multiply 0.46386719 with 2.
Since 0.92773438 is < 1. then add 0 to result
> Multiply 0.92773438 with 2.
Since 1.85546875 is >= 1. then add 1 to
result
> Multiply 0.85546875 with 2.
Since 1.71093750 is >= 1. then add 1 to
result
> Multiply 0.71093750 with 2.
Since 1.42187500 is >= 1. then add 1 to
result
> Multiply 0.42187500 with 2.
Since 0.84375000 is < 1. then add 0 to result
> Multiply 0.84375000 with 2.
Since 1.68750000 is >= 1. then add 1 to
result
> Multiply 0.68750000 with 2.
Since 1.37500000 is >= 1. then add 1 to
result
> 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.19899999999999807 of decimal is
.0011001011110001101010011111101111100111011011 in binary
so, 47.199 in binary is
101111.0011001011110001101010011111101111100111011011
-47.199 in simple binary =>
101111.0011001011110001101010011111101111100111011011
so, -47.199 in normal binary is
101111.0011001011110001101010011111101111100111011011 =>
1.011110011001011110001101010011111101111100111011011 *
2^5
64-bit format:
--------------------
sign bit is 1(-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
0111100110010111100011010100111111011111001110110110
so, -47.199 in 64-bit format is 1 10000000100
0111100110010111100011010100111111011111001110110110
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
1100000001000111100110010111100011010100111111011111001110110110 to
hexadecimal
1100 => C
0000 => 0
0100 => 4
0111 => 7
1001 => 9
1001 => 9
0111 => 7
1000 => 8
1101 => D
0100 => 4
1111 => F
1101 => D
1111 => F
0011 => 3
1011 => B
0110 => 6
So, in hexadecimal
1100000001000111100110010111100011010100111111011111001110110110 is
0xC0479978D4FDF3B6
in hexadecimal it is 0xC0479978D4FDF3B6