Skip to content
Tactiverge

Computer engineering

Fixed-width integers, bits and registers

Embedded C uses integer types with a fixed size, such as uint8_t, which holds 0 to 255, or int32_t, a signed 32-bit integer. Signed types normally use two's complement to represent negative numbers. When a result is too large for its type, it overflows: unsigned values wrap around to zero, while signed overflow is undefined behaviour in C and must be avoided. Bitwise operators work on individual bits. With a mask, code can set, clear, toggle or test one bit in a hardware register without disturbing the others.

Why it mattersA motor speed stored in an 8-bit variable that silently wraps from 255 to 0 can make a robot stop or lurch unexpectedly.

Learn it

  1. 1C types, sizes and integer overflowEmbedded Systems · Programming foundations
  2. 2Bitwise operations and hardware registersEmbedded Systems · Programming foundations