Understanding Bit Depths (1, 4, 8, 16, 24, 32 bits)

What are Bits and Bit Depth?

A bit is the most basic unit of data in computing, representing either a 0 or a 1. Bit depth refers to the number of bits used to represent a single piece of data. The more bits used, the more distinct values can be represented.

Understanding bit depths is crucial in systems like the Game Boy Advance because hardware components (like graphics, sound, memory registers) often expect data in very specific bit sizes. Using the correct bit depth affects memory usage, performance, and correctness.

Common Bit Depths Explained

1-bit

  • Number of Values: 21 = 2 (Typically 0 or 1)
  • Common Uses: Flags (on/off, true/false), simple masks.
  • GBA Context: Individual bits within hardware registers often act as flags (e.g., enabling/disabling features in REG_DISPCNT).

4-bit (Nibble)

  • Number of Values: 24 = 16 (0 to 15 decimal, 0 to F hex)
  • Common Uses: Representing a single hexadecimal digit, simple indexed color palettes (16 colors).
  • GBA Context: Used in 4bpp (bits per pixel) graphics modes for tiles and sprites, where each pixel's value is an index into a 16-color palette.

8-bit (Byte)

  • Number of Values: 28 = 256 (0 to 255 unsigned, -128 to 127 signed)
  • Common Uses: Characters (ASCII/UTF-8), small integer values, indexed color palettes (256 colors). It's a fundamental unit of memory addressing.
  • GBA Context: The `char`, `unsigned char`, `uint8_t`, `int8_t` data types. Used in 8bpp graphics modes (Mode 4 bitmap, 8bpp tiles/sprites). Memory is byte-addressable, although many hardware accesses are 16-bit or 32-bit aligned.

16-bit (Half-Word / Short)

  • Number of Values: 216 = 65,536
  • Common Uses: Medium-sized integers, sound samples, 16-bit color representation.
  • GBA Context: The `short`, `unsigned short`, `uint16_t`, `int16_t` data types. Crucially, many GBA hardware registers (like REG_DISPCNT, REG_BGxCNT, Timer registers, OAM attributes) are 16 bits wide. GBA Mode 3 uses 15-bit color (5 bits each for R, G, B), which fits within a 16-bit value.

24-bit

  • Number of Values: 224 = 16,777,216
  • Common Uses: Primarily used for representing "True Color" in graphics (8 bits each for Red, Green, and Blue channels). Less common as a standard integer data type in C.
  • GBA Context: While the GBA hardware itself uses 15-bit color (Mode 3) or indexed color, your source graphics assets (like PNG or BMP files) are often created using 24-bit RGB color before being converted/quantized to the GBA's format.

32-bit (Word / Long)

  • Number of Values: 232 = 4,294,967,296
  • Common Uses: Standard integer sizes on many systems, memory addresses in 32-bit architectures, floating-point numbers (single precision).
  • GBA Context: The `int`, `unsigned int`, `long`, `unsigned long`, `uint32_t`, `int32_t` data types (note `int` and `long` are both 32-bit on ARM). The GBA's ARM7TDMI CPU is a 32-bit processor. This means its internal registers are 32 bits wide, it processes data most naturally in 32-bit chunks, and it uses 32-bit memory addresses (allowing it to access up to 4GB of address space, although the GBA only maps specific regions within that space). DMA transfers can also operate in 32-bit units.

Summary Table

Bit Depth Common Name(s) Number of Values Typical GBA Uses / C Type
1-bitBit, Flag2Flags in registers
4-bitNibble16Hex digit, 4bpp palette index
8-bitByte256char, u8/i8, 8bpp palette index
16-bitHalf-Word, Short65,536short, u16/i16, Hardware Registers, Mode 3 Color
24-bit-~16.7 MillionSource Art Color (RGB888)
32-bitWord, Long~4.3 Billionint, long, u32/i32, CPU Registers, Memory Addresses, DMA

Why This Matters for GBA

Choosing the correct data types (which correspond to bit depths) in your C code is important for GBA development. Using a short (16-bit) to write to a 16-bit hardware register is more direct and often required compared to using an int (32-bit). Understanding that Mode 3 color is 15-bit helps you pack RGB values correctly into a short. Knowing the CPU is 32-bit informs you about efficient data handling and memory addressing capabilities. Being aware of these details helps you write code that works correctly and efficiently on the GBA hardware.