CS2650 PC Architecture

Data Representation – Numeric conversions

 

 

To convert a base 10 (decimal) number to its 32 bit floating point (IEEE754) representation:

 

  1. Convert the integer portion of the number to binary
  2. Convert the decimal portion of the number to binary
  3. Normalize the binary number by moving the point to the right of the leftmost 1 digit and then removing the left most 1 and any leading zeros.
  4. Count the number of places the point was moved
  5. Write out the floating point representation by:
    1. Writing a 1 for negative or 0 for positive
    2. Add the number of places the point was moved to 127 and convert to an 8 bit binary number
    3. Write those 8 bits following the sign bit
    4. Write the normalized number down
    5. Write enough zeros following to provide for a total of 32 bits
    6. Beginning at the left, divide the binary into groups of 4 and convert to hex
    7. The hex number is the correct representation of the 32 bit floating point value

 

To convert a 32 bit floating point number to its decimal equivalent:

 

1.                  Convert the hex number into binary

2.                  Separate the binary number into groups of 1, 8 and 23 bits

3.                  Calculate the number of places to move the binary point by

a.       Converting the 8 bit section into decimal and subtracting 127

4.                  Move the binary point in the 23 bit section to the right as calculated above beginning at the left with 0.

5.                  Add a 1 to the left of the 23 bit number

6.                  Convert left of the point to decimal

7.                  Convert the part to the right of the binary point to decimal

8.                  Write – if the first digit was a 1, + if the first digit was a zero

9.                  Write the integer portion

10.              Write the decimal portion

 

 

Examples:


 -1330.75 => C4A65800h

Flowchart: Alternate Process: Join the two numbers together:
10100110010.11
Flowchart: Alternate Process: -1330.75 Flowchart: Alternate Process: Convert 1330 to binary 10100110010
Flowchart: Alternate Process: Convert .75 to binary
.11
 





 

 

 

 

 

 

 

Flowchart: Alternate Process: Add enough trailing zeros to make up 32 bits
and divide by 4 bits from the left
1100 0100 1010 0110 0101 1000 0000 0000
Convert the number to Hex
C4A65800h
 

 

 

 

 

 

 

 

 


C4A65800h => -1330.75