Skip to Content
Navigation:
Cover for How Integers and Floats Work

How Integers and Floats Work

The way your computer does math is pretty weird. 4294967295 + 1 = 0! 0.1 + 0.2 = 0.30000000000000004! -2 in binary is 11111110! And what’s all this jargon? Unsigned integer? Little endian? Hexadecimal? This makes math seem unpredictable, which is very rude because math is the one thing in life that should be predictable.

Of course, the way computers do math is predictable — it just plays by slightly different rules than you might expect. And understanding how your computer does math unlocks a lot of things! You’ll:

  • know the limitations of your data types (“Oh, I should use a 64-bit integer for this, not a 32-bit int…” or “it’s fine to use a float here because…”)
  • be able to reason about WHY your computer is doing weird stuff with numbers (for example: why does echo '{ "id": 1648521499652009984 }' | jq '.' change the number from 1648521499652009984 to 1648521499652010000?)
  • unlocks a whole world of binary data and technical specifications you can read more easily (like Wireshark’s packet visualizations!)

And the way integers and floats are represented isn’t going to change (floating point was standardized in 1985!), so you only have to learn it once.

This zine will explain:

  • the jargon: signed/unsigned, little/big endian, 32 bit, bytes, hexadecimal, and more
  • why floating point math is so weird (and why a little weirdness is inevitable)
  • how integers and floats are represented in memory
  • exactly how floating numbers work, down to the binary representation
  • some alternatives to floating point

The zine also comes with a playground called memory spy where you can run programs and spy on the integers and floats in their memory.

I want this!

Credits!

  • Cover art by Vladimir Kašiković
  • Editing by Dolly Lanuza, and Kamal Marhubi
  • Pairing: Marie Claire LeBlanc Flanagan
  • Copy Editing by Gersande La Flèche
  • and thanks to all 60 beta readers <3

Commonly asked questions:

what's a zine?

According to Wikipedia:

A fanzine (blend of fan and magazine or -zine) is a non-professional and non-official publication produced by enthusiasts of a particular cultural phenomenon (such as a literary or musical genre) for the pleasure of others who share their interest.

The zines on this site are usually about 20 pages, and they’re full of short, informative, and fun comics which will quickly teach you something useful.

who are these zines for?

They’re aimed at working programmers, like me! The idea is that you’re busy, you want to know how to use some computer thing, and the man page makes your head hurt.

is the PDF version printable?

Yes! The PDF version of the zine includes special PDFs designed to be easy printable on a home printer. Print it out, staple it, fold it, read it, and then give it to a friend! It turns out it’s way easier to convince your friends to read a physical thing that is in front of them.

They all have black & white version to make sure they print well if you only have a black & white printer.

Table of Contents:

Take a peek inside:

© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)