Data Representation
Use this page to revise how numbers and text exist as bits on a microcontroller.
Bits, bytes, hex
A bit is 0 or 1. A byte is 8 bits. Hex groups bits in fours (0xFF is 255). Endianness is the byte order of a multi-byte value on a bus or in memory (little-endian is common on ARM and x86).
Integers
Unsigned integers wrap at \(2^n\). Two's complement encodes negative signed integers. Width matters: uint8_t vs. int32_t. Mixing signed and unsigned in C is a classic bug.
Fixed point vs. float
MCUs may lack a fast FPU. Fixed-point uses integers with an implied scale. IEEE-754 floats are convenient but cost cycles and can surprise you with rounding.
Starting Points
- C language fundamentals
- Kernighan & Ritchie, chapter 2 (types and operators), or any C reference on integer conversions.
Key Points
- You can convert a small integer between decimal, binary, and hex.
- You can explain unsigned wrap-around and two's complement.
- You can explain why fixed-width types (
stdint.h) are preferred in firmware. - You can say when float is acceptable vs. when you would use integer/fixed-point.
- You can define endianness and why it matters on a serial protocol.