Ch1_floating_point_numbers
Ch1_floating_point_numbers
Numbers
Mohammad Ali Javidian
Conversion between binary and
octal
Example: How many bits required to store the octal numbers, i.e., numbers in the
range of 0 to 7?
To convert an octal number to binary, expand each octal digit to its equivalent 3-bit
binary representation.
Example: Convert to binary.
To convert a binary number to octal, group the bits into sets of three, beginning at
the right of the binary number, and convert each resulting 3-bit binary to its
equivalent octal digit. If extra bits are needed on the left to make a set of three bits,
fill in with 0s.
Example: Convert to octal.
Conversion between binary and
hexadecimal
Example: How many bits required to store the hexadecimal numbers, i.e., numbers in
the range of 0 to 15?
To convert a hexadecimal number to binary, expand each hexadecimal digit to its
equivalent 4-bit binary representation.
Example: Convert to binary.
To convert a binary number to hexadecimal, group the bits into sets of four,
beginning at the right of the binary number, and convert each resulting 4-bit binary to
its equivalent hexadecimal digit. If extra bits are needed on the left to make a set of
three bits, fill in with 0s.
Example: Convert to hexadecimal.
Conversion between octal and
hexadecimal
To convert from octal to hexadecimal (and vice versa) directly, we
convert the given number to binary first and then we convert the
resulting binary to the requested base.
0 6 3 1 5
Sign Characteristic Mantissa
1) Convert to binary,
2) Write as normalized scientific notation with 1 before the binary point (i.e.,
the mantissa will always have a leading 1),
3) Determine the sign bit: 0 for positive numbers and 1 for negative
numbers,
4) Write the characteristic in binary 5 bits, i.e., ,
5) Drop 1. from the mantissa, pad to 10 bits and store,
6) Write as hexadecimal if needed & add the indicator 0x at the beginning.
Example: Convert 23.125 to 16bfp (16-bit floating-point).
Decimal to 32-bit Floating-Point :
(1 sign bit + 8-bit characteristic + 23-bit mantissa)