Building Software

Engineering Fundamentals for the Agent Era

Contents Section 3, The Machine

Representing Numbers, Text and Time

Mistakes to catch in review

  1. Money stored and calculated as floating-point numbers, producing totals that are off by a cent.

  2. String truncation or length checks that count bytes or code units and split an emoji or accented character in half.

  3. Timestamps saved without a time zone, so events shift by hours when a server moves region or the clocks change.

  4. Large integer IDs silently rounded when parsed as floating-point JSON numbers.

How computers store integers, decimals, text and timestamps, and the silent errors each representation invites.

Topics

Binary and Integers
Bits, bytes, signed and unsigned integers, and what happens when a value overflows.
Floating Point
How the IEEE 754 standard approximates real numbers, where precision is lost, and when that matters.
Decimals and Money
Decimal types, integer minor units such as cents, and explicit rounding rules for financial values.
Text and Unicode
Character sets, UTF-8, normalization and grapheme clusters, and why the length of a string is ambiguous.
Representing Time
Epoch time, UTC, time zones, daylight saving and calendar arithmetic, with local time treated as a display concern.
Serialization Formats
JSON, binary encodings and schemas, and what gets lost or changed when data crosses a boundary.

You understand it when you can

  • Explain why 0.1 + 0.2 does not equal 0.3 in most languages, and choose a representation for currency.
  • Store an event time and display it correctly to users in two different time zones, including across a daylight-saving change.
  • Explain the difference between bytes, code points and user-visible characters in UTF-8 text.

Drill

An agent wrote an invoice function that sums line items as floating-point numbers and accepts a payment only when the amount paid is exactly equal to that sum, and it stores the due date as a local-time string with no zone. Show why three line items of 0.10 produce a total that rejects a payment of 0.30, then find a customer location that sees the wrong due date.

Start here

Watch

Read

Code: The Hidden Language of Computer Hardware and Software

Charles Petzold, 2022, 2nd edition.

Builds up from bits and binary to integers, two's complement, character encoding and floating point, explaining why each representation has the limits it does.

Primary sources