Chapter 9: Specialized Processor Extensions
Exercise 1
Using a programming language that allows access to the byte representation of floating-point data types (such as C or C++), write a function that accepts a 32-bit single-precision variable as input. Extract the sign, exponent, and mantissa from the bytes of the floating-point variable and display them. Remove the bias term from the exponent before displaying its value and display the mantissa as a decimal number. Test the program with the values 0, -0, 1, -1, 6.674e-11, 1.0e38, 1.0e39, 1.0e-38, and 1.0e-39. The numeric values listed here containing e are using the C/C++ text representation of floating-point numbers. For example, 6.674e-11 means 6.674 x 10-11.
Answer
The Ex__1_float_format.cpp
C++ file contains the code for this exercise:
// Ex__1_float_format.cpp
#include <iostream>
#include <cstdint>
void print_float(float f)
{
const auto bytes = static_cast<uint8_t*>(static_cast<void...