[IEEE 754] Understanding the IEEE 754 Float32 Representation

Heechul Yoon·2023년 10월 29일
0

In modern computers, data is primarily stored in binary format, with integers being the most straightforward and well-understood type of data for computational tasks. To handle different types of calculations, many computers are equipped with both a main processor and a coprocessor. The main processor typically focuses on integer calculations, while the coprocessor specializes in floating-point arithmetic.

During the era of x86-16 architecture, the 8088 CPU and the 8087 coprocessor were commonly used together. The 8088 handled integer-based calculations, and the 8087 was employed to assist with floating-point operations. This division of labor allowed for more efficient and faster computations.

before we go, we need to know what is exponential notation

Exponential Notaion
Exponential notation is a method used for normalizing data. For instance, the number 127.3424 can be represented as 1.273424 * e+2, where 1.273424 is the mantissa and 10^2 is the exponent.

breaking down how 127.3424 is stored as a Float32

Transforming the Integer Part

The integer part 127(10) in decimal is equivalent to 01111111(2) in binary.

Transforming the Fractional Part

The fractional part 0.3424(10) in decimal can be approximated as 0.010101....(2) in binary.
Combining these, the binary representation becomes 1111111.010101....(2)

Normalizing the Transformed Data

Upon normalization, the number becomes 1.111111010101…*2^6.

  • The mantissa becomes 1.111111010101...
  • The exponent is 2^6, but we only store 6 since it's understood that this is a binary exponent.

Adding Bias to the Exponent

What Is Bias?
The exponent can be either positive or negative. For instance, if the original data is less than 1, the exponent could be negative like 2^-6(we only store -6 on the memory). This is where bias (typically 127 for float32) comes into play.

Adding 127 to the exponent 6, we get 133, which in binary is 10000101.

  • If the biased exponent is between 0 and 127, the actual exponent is negative.
  • If the biased exponent is between 128 and 255, the actual exponent is positive.

Result

In the end, the float32 representation would be:

  • Sign bit: 0
  • Exponent: 10000101
  • Mantissa: 11111101010101010101010, truncated to fit the 23-bit field for float32.

This provides an approximate but efficient representation of the number 127.3424 in IEEE 754 float32 format.

profile
Quit talking, Begin doing

0개의 댓글