Fixed-Point and Floating-Point Basics
What you'll learn: How computers represent numbers with fractional parts like 3.14 or 0.5 using two different strategies.
The Challenge of Fractions in Binary
So far, you've worked with whole numbers (integers) in binary. But what happens when you need to represent 5.75 or 0.125? Computers can't just add a decimal point — they only understand 1s and 0s. We need a systematic way to represent fractional values.
Fixed-Point Representation
Think of fixed-point like drawing a permanent line on a ruler. You decide ahead of time: "The first 4 bits represent the whole number part, and the last 4 bits represent the fraction."
For example, if you reserve 4 bits for fractions:
00101100might mean0010.1100in binary- The whole part
0010= 2 in decimal - The fractional part
.1100= 1/2 + 1/4 = 0.75 - Total: 2.75
The "point" stays fixed in the same position for all numbers — simple but inflexible.
Floating-Point Representation
Floating-point is like scientific notation: instead of a fixed decimal position, you store a number as sign × significand × 2^exponent. The "point" can float to different positions, letting you represent both tiny numbers (0.0000001) and huge ones (999999999) efficiently.
Think of it as: 3.14 × 10^0 versus 3.14 × 10^8 — same digits, different scale. Computers do this in binary, storing the sign bit, exponent bits, and significand (mantissa) bits separately.
This flexibility makes floating-point the standard for most fractional calculations in programming.
Key Takeaway: Fixed-point keeps the binary point in one position (simple, limited range), while floating-point moves it around (complex, huge range) — most computers use floating-point for fractions.