liveBook · Manning

Binary representation

As explained in Modern C

A binary representation is the abstract model of the values and operation results of a type on a particular platform.

A binary representation is the abstract model of a type’s possible values and operation results on a particular platform. It is distinct from an object representation, which describes how values are stored in memory. The same value may therefore have different binary representations. section 5.1.3 section 5.7

A type’s binary representation determines the results of its operations and remains observable through operands, operators, library calls, and named platform values. For size_t, inspecting SIZE_MAX together with the operands can determine its arithmetic behavior. section 5.1.3

Unsigned integers provide the clearest model:

  • Representable values range from 0 through N − 1, where N is determined by the type’s precision. section 5.7.1
  • Represent non-negative values with bits whose positions contribute powers of two; the lowest and highest positions are the least- and most-significant bits. section 5.7.1
  • Wrap arithmetic modulo N, so the maximum value is 2^p − 1 and arithmetic is determined by precision p. section 5.7.1

A sixteen-bit unsigned value

For an unsigned type with precision 16, the value 240 sets bits b4 through b7 and clears the others. Its least-significant set bit is b4; its most-significant set bit is b7. The first unrepresentable value is 2^16, so the maximum is 2^16 − 1. section 5.7.1

Table 5.4. Bounds for scalar types used in this book (view table figure)

Name

[min, max]

Where

Typical

size_t [0, SIZE_MAX] <stdint.h> [0, 2w –1], w = 32, 64
double [±DBL_MIN, ±DBL_MAX] <float.h> [±2–w–2,±2w], w = 1024
signed [INT_MIN, INT_MAX] <limits.h> [–2w, 2w –1], w = 31
unsigned [0, UINT_MAX] <limits.h> [0, 2w –1], w = 32
bool [false, true] <stdbool.h> [0, 1]
ptrdiff_t [PTRDIFF_MIN, PTRDIFF_MAX] <stdint.h> [–2w, 2w –1], w = 31, 63
char [CHAR_MIN, CHAR_MAX] <limits.h> [0, 2w –1], w = 7, 8
unsigned char [0, UCHAR_MAX ] <limits.h> [0, 255]

Compare bounds for size_t, signed and unsigned integers, bool, character types, pointers, and floating-point values. section 5.7.1

Binary representation belongs to C’s abstract state machine: values, types, and representations determine state transitions independently of a computer’s physical storage. Object representation matters when manipulating memory or communicating across differing platform models. section 5.1.3 section 12.8

How Modern C covers it

How deep it goes
Defines the model and develops unsigned-bit arithmetic, while deferring physical storage to object representation.
Examples
Uses SIZE_MAX, a sixteen-bit unsigned value of 240, bit positions, and scalar-type bounds.
What you can do after
Evaluate operation behavior from type ranges, precision, operands, and observable platform limits.
How it connects
Connects abstract state machines, object representation, unsigned integers, precision, overflow, and the C memory model.

Also explained in

Compare how 6 books explain binary representation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.