Skip to Content

A stick figure smiling

Here's a preview from my zine, How Integers and Floats Work! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!


panel 1:

To decode bytes as integers, we need to know 3 things: 1. the integer’s size (8 bit, 16 bit, 32 bit, or 64 bit) 2. is it little or big endian? 3. is it signed or unsigned?

panel 2:

how signed integers work is the hardest part) to understand (I only learned how it works a couple months ago!). Just knowing that unsigned and signed integers are different will take you a long way.

2 bytes, 3 interpretations

254 | 0

We could interpret these 2 bytes as: 1. 254 (little endian) 2. 65024 (big endian, unsigned) 3. -512 (big endian, signed)

how you decode bytes depends on the context

  • in a program’s memory, the type of the variable tells you the integer’s size and if it’s signed/unsigned
  • your CPU determines if integers are big or little endian (you don’t have a choice)
  • for a binary network protocol (like DNS), the specification (for DNS, that’s RFC 1035) will tell you how to decode the bytes

examples of types

  • in Rust, an i64 is a signed 64-bit integer
  • in Go, a uint32 is an unsigned 32-bit integer
  • in C, a short is usually a signed 16-bit integer, depending on the platform

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)