foundation Estimated learning time: 12 h

P-1.3 Numbers, Text, and Why They Go Wrong

You can explain integer overflow and floating-point rounding, say why two decimal numbers can fail an equality check, and describe what a character encoding does.

Two families of defect follow programmers through their whole working life, and both come from the same place: a finite machine representing infinite things. Integers wrap and decimals round. Text is worse, because bytes and characters look identical until somebody types a name your program was never tested on. Learning this now costs an afternoon; learning it from a production incident costs considerably more.

Work through these

  • Integers have a range, and going past it wraps around

    A fixed number of bits holds a fixed range of whole numbers, and arithmetic that leaves the range does not raise its hand in every language. It quietly produces a wrong and often negative answer.

  • Floating point stores approximations, and the rounding is systematic

    Decimal fractions rarely have an exact representation in binary, so a stored value is usually a very near neighbour of the number you wrote. The error is predictable rather than random, which is what makes it possible to reason about.

  • Why comparing two decimal results for equality is the wrong test

    Two calculations that should agree mathematically can differ in the last bits, so an equality check fails on numbers that are correct. The usual answer is to ask whether they differ by less than a tolerance you choose deliberately.

  • Bytes and characters are not the same thing

    An encoding is the agreement about which bytes stand for which characters, and text handled without knowing its encoding is bytes pretending to be words. This is where names, currency symbols and Indian language text break.

    CS50x: Introduction to Computer Science · Course
  • Reproduce one overflow and one rounding surprise, and explain both

    Write the two smallest programs that show a wrapped integer and a failed decimal comparison. Having produced them yourself, you will recognise the shape of both defects when they turn up inside something larger.

Sign in to keep your progress.

Free resources

We haven't checked most of these for screen reader use yet.

Links last checked 31 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.