Floating-Point to Fixed-Point Conversion Explained with C Code

This page details the conversion between floating-point and fixed-point representations, along with a C code example for performing these conversions. The provided C program handles the conversion of two separate I (real) and Q (imaginary) files between formats as per your selection.

If you’re converting from floating-point to fixed-point, ensure your real_in and imag_in files are in floating-point format. The results will be written to real_out and imag_out. You’ll need to create a header file named macro1.h and save the contents described later.

The C program below also handles the conversion of Hex numbers to integer (decimal) format and vice versa, supporting both positive and negative values.

Important: When converting from Hex to integer, you may need to adjust the value 32768 (highlighted in red in the code - see the downloadable file) to match the appropriate Q format you are using. The example provided is configured for a Q15 format.

This program is particularly useful for converting Analog-to-Digital Converter (ADC) output in communication receivers, aiding in analysis and debugging. Often, ADCs output or write hexadecimal data to interfaced memory on the board.

Example: Hex to Decimal (Fixed Point Integer) and Vice Versa

This example demonstrates conversion between hexadecimal and decimal (fixed-point integer) representations.