In: Computer Science
convert -549.675 to IEEE-754 single precision and double
precision both.
Need a lot of explanation. (Atleast 1000 words)
1)
-549.675
Converting 549.675 to binary
Convert decimal part first, then the fractional
part
> First convert 549 to binary
Divide 549 successively by 2 until the quotient is
0
> 549/2 = 274, remainder is
1
> 274/2 = 137, remainder is
0
> 137/2 = 68, remainder is
1
> 68/2 = 34, remainder is
0
> 34/2 = 17, remainder is
0
> 17/2 = 8, remainder is 1
> 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
1000100101
So, 549 of decimal is 1000100101 in binary
> Now, Convert 0.67500000 to binary
> Multiply 0.67500000 with 2.
Since 1.35000000 is >= 1. then add 1 to
result
> Multiply 0.35000000 with 2.
Since 0.70000000 is < 1. then add 0 to result
> Multiply 0.70000000 with 2.
Since 1.40000000 is >= 1. then add 1 to
result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.59999999 is >= 1. then add 1 to
result
> Multiply 0.59999999 with 2.
Since 1.19999999 is >= 1. then add 1 to
result
> Multiply 0.19999999 with 2.
Since 0.39999998 is < 1. then add 0 to result
> Multiply 0.39999998 with 2.
Since 0.79999995 is < 1. then add 0 to result
> Multiply 0.79999995 with 2.
Since 1.59999990 is >= 1. then add 1 to
result
> Multiply 0.59999990 with 2.
Since 1.19999981 is >= 1. then add 1 to
result
> Multiply 0.19999981 with 2.
Since 0.39999962 is < 1. then add 0 to result
> Multiply 0.39999962 with 2.
Since 0.79999924 is < 1. then add 0 to result
> Multiply 0.79999924 with 2.
Since 1.59999847 is >= 1. then add 1 to
result
> Multiply 0.59999847 with 2.
Since 1.19999695 is >= 1. then add 1 to
result
> Multiply 0.19999695 with 2.
Since 0.39999390 is < 1. then add 0 to result
> Multiply 0.39999390 with 2.
Since 0.79998779 is < 1. then add 0 to result
> Multiply 0.79998779 with 2.
Since 1.59997559 is >= 1. then add 1 to
result
> Multiply 0.59997559 with 2.
Since 1.19995117 is >= 1. then add 1 to
result
> Multiply 0.19995117 with 2.
Since 0.39990234 is < 1. then add 0 to result
> Multiply 0.39990234 with 2.
Since 0.79980469 is < 1. then add 0 to result
> Multiply 0.79980469 with 2.
Since 1.59960938 is >= 1. then add 1 to
result
> Multiply 0.59960938 with 2.
Since 1.19921875 is >= 1. then add 1 to
result
> Multiply 0.19921875 with 2.
Since 0.39843750 is < 1. then add 0 to result
> Multiply 0.39843750 with 2.
Since 0.79687500 is < 1. then add 0 to result
> Multiply 0.79687500 with 2.
Since 1.59375000 is >= 1. then add 1 to
result
> Multiply 0.59375000 with 2.
Since 1.18750000 is >= 1. then add 1 to
result
> Multiply 0.18750000 with 2.
Since 0.37500000 is < 1. then add 0 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.6749999999999545 of decimal is
.101011001100110011001100110011001100110011 in binary
so, 549.675 in binary is
1000100101.101011001100110011001100110011001100110011
-549.675 in simple binary =>
1000100101.101011001100110011001100110011001100110011
so, -549.675 in normal binary is
1000100101.101011001100110011001100110011001100110011 =>
1.00010010110101100110011 * 2^9
single precision:
--------------------
sign bit is 1(-ve)
exponent bits are (127+9=136) => 10001000
Divide 136 successively by 2 until the quotient is
0
> 136/2 = 68, remainder is
0
> 68/2 = 34, remainder is
0
> 34/2 = 17, remainder is
0
> 17/2 = 8, remainder is 1
> 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
10001000
So, 136 of decimal is 10001000 in binary
frac/significant bits are 00010010110101100110011
so, -549.675 in single-precision format is 1 10001000
00010010110101100110011
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 11000100000010010110101100110011 to hexadecimal
1100 => C
0100 => 4
0000 => 0
1001 => 9
0110 => 6
1011 => B
0011 => 3
0011 => 3
So, in hexadecimal 11000100000010010110101100110011 is
0xC4096B33
in hexadecimal it is 0xC4096B33
2)
-549.675
Converting 549.675 to binary
Convert decimal part first, then the fractional
part
> First convert 549 to binary
Divide 549 successively by 2 until the quotient is
0
> 549/2 = 274, remainder is
1
> 274/2 = 137, remainder is
0
> 137/2 = 68, remainder is
1
> 68/2 = 34, remainder is
0
> 34/2 = 17, remainder is
0
> 17/2 = 8, remainder is 1
> 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
1000100101
So, 549 of decimal is 1000100101 in binary
> Now, Convert 0.67500000 to binary
> Multiply 0.67500000 with 2.
Since 1.35000000 is >= 1. then add 1 to
result
> Multiply 0.35000000 with 2.
Since 0.70000000 is < 1. then add 0 to result
> Multiply 0.70000000 with 2.
Since 1.40000000 is >= 1. then add 1 to
result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.60000000 is >= 1. then add 1 to
result
> Multiply 0.60000000 with 2.
Since 1.20000000 is >= 1. then add 1 to
result
> Multiply 0.20000000 with 2.
Since 0.40000000 is < 1. then add 0 to result
> Multiply 0.40000000 with 2.
Since 0.80000000 is < 1. then add 0 to result
> Multiply 0.80000000 with 2.
Since 1.59999999 is >= 1. then add 1 to
result
> Multiply 0.59999999 with 2.
Since 1.19999999 is >= 1. then add 1 to
result
> Multiply 0.19999999 with 2.
Since 0.39999998 is < 1. then add 0 to result
> Multiply 0.39999998 with 2.
Since 0.79999995 is < 1. then add 0 to result
> Multiply 0.79999995 with 2.
Since 1.59999990 is >= 1. then add 1 to
result
> Multiply 0.59999990 with 2.
Since 1.19999981 is >= 1. then add 1 to
result
> Multiply 0.19999981 with 2.
Since 0.39999962 is < 1. then add 0 to result
> Multiply 0.39999962 with 2.
Since 0.79999924 is < 1. then add 0 to result
> Multiply 0.79999924 with 2.
Since 1.59999847 is >= 1. then add 1 to
result
> Multiply 0.59999847 with 2.
Since 1.19999695 is >= 1. then add 1 to
result
> Multiply 0.19999695 with 2.
Since 0.39999390 is < 1. then add 0 to result
> Multiply 0.39999390 with 2.
Since 0.79998779 is < 1. then add 0 to result
> Multiply 0.79998779 with 2.
Since 1.59997559 is >= 1. then add 1 to
result
> Multiply 0.59997559 with 2.
Since 1.19995117 is >= 1. then add 1 to
result
> Multiply 0.19995117 with 2.
Since 0.39990234 is < 1. then add 0 to result
> Multiply 0.39990234 with 2.
Since 0.79980469 is < 1. then add 0 to result
> Multiply 0.79980469 with 2.
Since 1.59960938 is >= 1. then add 1 to
result
> Multiply 0.59960938 with 2.
Since 1.19921875 is >= 1. then add 1 to
result
> Multiply 0.19921875 with 2.
Since 0.39843750 is < 1. then add 0 to result
> Multiply 0.39843750 with 2.
Since 0.79687500 is < 1. then add 0 to result
> Multiply 0.79687500 with 2.
Since 1.59375000 is >= 1. then add 1 to
result
> Multiply 0.59375000 with 2.
Since 1.18750000 is >= 1. then add 1 to
result
> Multiply 0.18750000 with 2.
Since 0.37500000 is < 1. then add 0 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.6749999999999545 of decimal is
.101011001100110011001100110011001100110011 in binary
so, 549.675 in binary is
1000100101.101011001100110011001100110011001100110011
-549.675 in simple binary =>
1000100101.101011001100110011001100110011001100110011
so, -549.675 in normal binary is
1000100101.101011001100110011001100110011001100110011 =>
1.000100101101011001100110011001100110011001100110011 *
2^9
64-bit format:
--------------------
sign bit is 1(-ve)
exponent bits are (1023+9=1032) => 10000001000
Divide 1032 successively by 2 until the quotient is
0
> 1032/2 = 516, remainder is
0
> 516/2 = 258, remainder is
0
> 258/2 = 129, remainder is
0
> 129/2 = 64, remainder is
1
> 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
10000001000
So, 1032 of decimal is 10000001000 in binary
frac/significant bits are
0001001011010110011001100110011001100110011001100110
so, -549.675 in 64-bit format is 1 10000001000
0001001011010110011001100110011001100110011001100110
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
1100000010000001001011010110011001100110011001100110011001100110 to
hexadecimal
1100 => C
0000 => 0
1000 => 8
0001 => 1
0010 => 2
1101 => D
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
0110 => 6
So, in hexadecimal
1100000010000001001011010110011001100110011001100110011001100110 is
0xC0812D6666666666
in hexadecimal it is
0xC0812D6666666666