Programming foundations

Stage 3 · Lesson 3 of 9

Integers and overflow

How computers run your code

In most languages, integers are stored in a fixed number of . A 32-bit signed int holds roughly minus 2.1 billion to plus 2.1 billion, and a 64-bit one about 9.2 × 10^18. Negative numbers use , a scheme where the top bit acts as the sign.

Go past the limit and you get . Java and C# wrap silently to a large negative number by default, and in C++ signed overflow is undefined behaviour. Python integers grow as large as memory allows.

JavaScript numbers stop being exact above 2^53, which is why BigInt exists. Overflow bugs show up in money totals, and counters, so know the limits of the types you use.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Keep handy

  • Quick explanations of OS basics like processes and memory when a lecture skips a step

Also worth your time

  • Everything from a key press to a rendered page; read it after this stage

Mark this stage as not done?