In: Computer Science
convert -4972.67 to IEEE-754 single precision and double
precision both.
Need a lot of explanation. (Atleast 1000 words)
a)
-4972.67
Converting 4972.67 to binary
Convert decimal part first, then the fractional
part
> First convert 4972 to binary
Divide 4972 successively by 2 until the quotient is
0
> 4972/2 = 2486, remainder is
0
> 2486/2 = 1243, remainder is
0
> 1243/2 = 621, remainder is
1
> 621/2 = 310, remainder is
1
> 310/2 = 155, remainder is
0
> 155/2 = 77, remainder is
1
> 77/2 = 38, remainder is
1
> 38/2 = 19, remainder is
0
> 19/2 = 9, remainder is 1
> 9/2 = 4, remainder is 1
> 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
1001101101100
So, 4972 of decimal is 1001101101100 in binary
> Now, Convert 0.67000000 to binary
> Multiply 0.67000000 with 2.
Since 1.34000000 is >= 1. then add 1 to
result
> Multiply 0.34000000 with 2.
Since 0.68000000 is < 1. then add 0 to result
> Multiply 0.68000000 with 2.
Since 1.36000000 is >= 1. then add 1 to
result
> Multiply 0.36000000 with 2.
Since 0.72000000 is < 1. then add 0 to result
> Multiply 0.72000000 with 2.
Since 1.44000000 is >= 1. then add 1 to
result
> Multiply 0.44000000 with 2.
Since 0.88000000 is < 1. then add 0 to result
> Multiply 0.88000000 with 2.
Since 1.76000000 is >= 1. then add 1 to
result
> Multiply 0.76000000 with 2.
Since 1.52000000 is >= 1. then add 1 to
result
> Multiply 0.52000000 with 2.
Since 1.04000000 is >= 1. then add 1 to
result
> Multiply 0.04000000 with 2.
Since 0.08000000 is < 1. then add 0 to result
> Multiply 0.08000000 with 2.
Since 0.16000000 is < 1. then add 0 to result
> Multiply 0.16000000 with 2.
Since 0.32000000 is < 1. then add 0 to result
> Multiply 0.32000000 with 2.
Since 0.64000000 is < 1. then add 0 to result
> Multiply 0.64000000 with 2.
Since 1.28000000 is >= 1. then add 1 to
result
> Multiply 0.28000000 with 2.
Since 0.56000000 is < 1. then add 0 to result
> Multiply 0.56000000 with 2.
Since 1.12000000 is >= 1. then add 1 to
result
> Multiply 0.12000000 with 2.
Since 0.24000001 is < 1. then add 0 to result
> Multiply 0.24000001 with 2.
Since 0.48000002 is < 1. then add 0 to result
> Multiply 0.48000002 with 2.
Since 0.96000004 is < 1. then add 0 to result
> Multiply 0.96000004 with 2.
Since 1.92000008 is >= 1. then add 1 to
result
> Multiply 0.92000008 with 2.
Since 1.84000015 is >= 1. then add 1 to
result
> Multiply 0.84000015 with 2.
Since 1.68000031 is >= 1. then add 1 to
result
> Multiply 0.68000031 with 2.
Since 1.36000061 is >= 1. then add 1 to
result
> Multiply 0.36000061 with 2.
Since 0.72000122 is < 1. then add 0 to result
> Multiply 0.72000122 with 2.
Since 1.44000244 is >= 1. then add 1 to
result
> Multiply 0.44000244 with 2.
Since 0.88000488 is < 1. then add 0 to result
> Multiply 0.88000488 with 2.
Since 1.76000977 is >= 1. then add 1 to
result
> Multiply 0.76000977 with 2.
Since 1.52001953 is >= 1. then add 1 to
result
> Multiply 0.52001953 with 2.
Since 1.04003906 is >= 1. then add 1 to
result
> Multiply 0.04003906 with 2.
Since 0.08007812 is < 1. then add 0 to result
> Multiply 0.08007812 with 2.
Since 0.16015625 is < 1. then add 0 to result
> Multiply 0.16015625 with 2.
Since 0.32031250 is < 1. then add 0 to result
> Multiply 0.32031250 with 2.
Since 0.64062500 is < 1. then add 0 to result
> Multiply 0.64062500 with 2.
Since 1.28125000 is >= 1. then add 1 to
result
> Multiply 0.28125000 with 2.
Since 0.56250000 is < 1. then add 0 to result
> Multiply 0.56250000 with 2.
Since 1.12500000 is >= 1. then add 1 to
result
> Multiply 0.12500000 with 2.
Since 0.25000000 is < 1. then add 0 to result
> Multiply 0.25000000 with 2.
Since 0.50000000 is < 1. then add 0 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.6700000000000728 of decimal is
.101010111000010100011110101110000101001 in binary
so, 4972.67 in binary is
1001101101100.101010111000010100011110101110000101001
-4972.67 in simple binary =>
1001101101100.101010111000010100011110101110000101001
so, -4972.67 in normal binary is
1001101101100.101010111000010100011110101110000101001 =>
1.001101101100101010111 * 2^12
single precision:
--------------------
sign bit is 1(-ve)
exponent bits are (127+12=139) => 10001011
Divide 139 successively by 2 until the quotient is
0
> 139/2 = 69, remainder is
1
> 69/2 = 34, remainder is
1
> 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
10001011
So, 139 of decimal is 10001011 in binary
frac/significant bits are 00110110110010101011100
so, -4972.67 in single-precision format is 1 10001011
00110110110010101011100
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 11000101100110110110010101011100 to hexadecimal
1100 => C
0101 => 5
1001 => 9
1011 => B
0110 => 6
0101 => 5
0101 => 5
1100 => C
So, in hexadecimal 11000101100110110110010101011100 is
0xC59B655C
in hexadecimal it is 0xC59B655C
b)
-4972.67
Converting 4972.67 to binary
Convert decimal part first, then the fractional
part
> First convert 4972 to binary
Divide 4972 successively by 2 until the quotient is
0
> 4972/2 = 2486, remainder is
0
> 2486/2 = 1243, remainder is
0
> 1243/2 = 621, remainder is
1
> 621/2 = 310, remainder is
1
> 310/2 = 155, remainder is
0
> 155/2 = 77, remainder is
1
> 77/2 = 38, remainder is
1
> 38/2 = 19, remainder is
0
> 19/2 = 9, remainder is 1
> 9/2 = 4, remainder is 1
> 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
1001101101100
So, 4972 of decimal is 1001101101100 in binary
> Now, Convert 0.67000000 to binary
> Multiply 0.67000000 with 2.
Since 1.34000000 is >= 1. then add 1 to
result
> Multiply 0.34000000 with 2.
Since 0.68000000 is < 1. then add 0 to result
> Multiply 0.68000000 with 2.
Since 1.36000000 is >= 1. then add 1 to
result
> Multiply 0.36000000 with 2.
Since 0.72000000 is < 1. then add 0 to result
> Multiply 0.72000000 with 2.
Since 1.44000000 is >= 1. then add 1 to
result
> Multiply 0.44000000 with 2.
Since 0.88000000 is < 1. then add 0 to result
> Multiply 0.88000000 with 2.
Since 1.76000000 is >= 1. then add 1 to
result
> Multiply 0.76000000 with 2.
Since 1.52000000 is >= 1. then add 1 to
result
> Multiply 0.52000000 with 2.
Since 1.04000000 is >= 1. then add 1 to
result
> Multiply 0.04000000 with 2.
Since 0.08000000 is < 1. then add 0 to result
> Multiply 0.08000000 with 2.
Since 0.16000000 is < 1. then add 0 to result
> Multiply 0.16000000 with 2.
Since 0.32000000 is < 1. then add 0 to result
> Multiply 0.32000000 with 2.
Since 0.64000000 is < 1. then add 0 to result
> Multiply 0.64000000 with 2.
Since 1.28000000 is >= 1. then add 1 to
result
> Multiply 0.28000000 with 2.
Since 0.56000000 is < 1. then add 0 to result
> Multiply 0.56000000 with 2.
Since 1.12000000 is >= 1. then add 1 to
result
> Multiply 0.12000000 with 2.
Since 0.24000001 is < 1. then add 0 to result
> Multiply 0.24000001 with 2.
Since 0.48000002 is < 1. then add 0 to result
> Multiply 0.48000002 with 2.
Since 0.96000004 is < 1. then add 0 to result
> Multiply 0.96000004 with 2.
Since 1.92000008 is >= 1. then add 1 to
result
> Multiply 0.92000008 with 2.
Since 1.84000015 is >= 1. then add 1 to
result
> Multiply 0.84000015 with 2.
Since 1.68000031 is >= 1. then add 1 to
result
> Multiply 0.68000031 with 2.
Since 1.36000061 is >= 1. then add 1 to
result
> Multiply 0.36000061 with 2.
Since 0.72000122 is < 1. then add 0 to result
> Multiply 0.72000122 with 2.
Since 1.44000244 is >= 1. then add 1 to
result
> Multiply 0.44000244 with 2.
Since 0.88000488 is < 1. then add 0 to result
> Multiply 0.88000488 with 2.
Since 1.76000977 is >= 1. then add 1 to
result
> Multiply 0.76000977 with 2.
Since 1.52001953 is >= 1. then add 1 to
result
> Multiply 0.52001953 with 2.
Since 1.04003906 is >= 1. then add 1 to
result
> Multiply 0.04003906 with 2.
Since 0.08007812 is < 1. then add 0 to result
> Multiply 0.08007812 with 2.
Since 0.16015625 is < 1. then add 0 to result
> Multiply 0.16015625 with 2.
Since 0.32031250 is < 1. then add 0 to result
> Multiply 0.32031250 with 2.
Since 0.64062500 is < 1. then add 0 to result
> Multiply 0.64062500 with 2.
Since 1.28125000 is >= 1. then add 1 to
result
> Multiply 0.28125000 with 2.
Since 0.56250000 is < 1. then add 0 to result
> Multiply 0.56250000 with 2.
Since 1.12500000 is >= 1. then add 1 to
result
> Multiply 0.12500000 with 2.
Since 0.25000000 is < 1. then add 0 to result
> Multiply 0.25000000 with 2.
Since 0.50000000 is < 1. then add 0 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.6700000000000728 of decimal is
.101010111000010100011110101110000101001 in binary
so, 4972.67 in binary is
1001101101100.101010111000010100011110101110000101001
-4972.67 in simple binary =>
1001101101100.101010111000010100011110101110000101001
so, -4972.67 in normal binary is
1001101101100.101010111000010100011110101110000101001 =>
1.001101101100101010111000010100011110101110000101001 *
2^12
64-bit format:
--------------------
sign bit is 1(-ve)
exponent bits are (1023+12=1035) => 10000001011
Divide 1035 successively by 2 until the quotient is
0
> 1035/2 = 517, remainder is
1
> 517/2 = 258, remainder is
1
> 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
10000001011
So, 1035 of decimal is 10000001011 in binary
frac/significant bits are
0011011011001010101110000101000111101011100001010010
so, -4972.67 in 64-bit format is 1 10000001011
0011011011001010101110000101000111101011100001010010
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
1100000010110011011011001010101110000101000111101011100001010010 to
hexadecimal
1100 => C
0000 => 0
1011 => B
0011 => 3
0110 => 6
1100 => C
1010 => A
1011 => B
1000 => 8
0101 => 5
0001 => 1
1110 => E
1011 => B
1000 => 8
0101 => 5
0010 => 2
So, in hexadecimal
1100000010110011011011001010101110000101000111101011100001010010 is
0xC0B36CAB851EB852
in hexadecimal it is
0xC0B36CAB851EB852