A pc’s native tongue is binary, the well-known ones and zeros worshiped by early mainframe programmers. Clumped into bytes and phrases, these digits simply signify an armada of integers, each optimistic and destructive values. However what about fractions, decimal values, large numbers, and teeny tiny numbers? What’s the key to their storage?
A few years in the past, groups of pc scientists in white lab coats got here up with the IEEE 754 Normal for floating level arithmetic on pc methods. This commonplace kinds the premise of how actual numbers are offered in and utilized by programming languages.
In C, the float knowledge sort is outlined as a single precision floating-point worth. Additionally known as binary32, it consists of 32 bits of data which signify values within the vary of three.4 × 1038 by means of 1.2 × 10-38, optimistic and destructive. This vary is extremely vary, which is the place the precision half comes into play.
The one precision of a float implies that the worth represented is correct as much as about seven digits. Formally, the precision is outlined as wherever between six to 9 vital decimal digits. For nearly all mathematical operations, such precision is satisfactory; the double knowledge sort affords twice as a lot precision when required.
I’m curious how such data is saved inside 32 bits. Clearly, one thing sneaky have to be happening.
Determine 1 illustrates how 32 bits of binary knowledge is split when representing an actual quantity.
Determine 1. The deets on how an actual quantity is saved in binary.
The bits are organized into three clumps:
- An indication bit, optimistic or destructive
- Eight exponent bits, which set the worth’s magnitude (measurement)
- Twenty-three fraction bits, the worth itself additionally referred to as the mantissa or significand
To witness this storage, I’m exploiting the weak spot of a C language union by setting a float worth however then analyzing it as a lengthy int. This strategy lets me peek on the bytes contained in the single-precision worth and output the consequence to replicate what you see in Determine 1. Right here’s the code:
2026_10_24-Lesson.c
#embrace <stdio.h>
int essential()
{
union actual {
float a;
lengthy b;
};
union actual numb;
int x;
printf("Enter a price: ");
scanf("%f",&numb.a);
printf("The worth %f is saved as: ",numb.a);
for( x=0; x<32; x++ )
{
if( x==1 || x==9 )
{
putchar(' ');
}
putchar( numb.b & 0x80000000 ? '1' : '0' );
numb.b <<= 1;
}
putchar('n');
return 0;
}
This system prompts for an actual quantity. The worth is then displayed, together with every of the bits as saved within the binary32 format. The union actual permits me to entry the float inside numb.a as lengthy int numb.b. A for loop plows by means of every of the 32 bits, outputting a one or zero within the correct place, together with an area between the signal bit and exponent bits in addition to the exponent bits and the fraction bits.
Right here’s a pattern run:
Enter a price: 12.375 The worth 12.375000 is saved as: 0 10000010 10001100000000000000000
This output precisely reveals how the worth 12.375 is represented as an actual quantity within the binary32 format, a float. In fact, what you see are simply bits they usually don’t precisely clarify a lot. For subsequent week’s Lesson, I cut up this worth into its integer parts, which is the following step towards understanding what every clump represents.

