data-structuresterminology

Name of binary data structures that contain fixed-length components?


I'm trying to document how I'm doing something to other developers and I'm struggling to reduce the explanation down other than explain exactly what I'm doing at every step. It's been a couple of decades since I did formal data structures at uni so wondered if somebody could help me formally explain it. Here's the long-form...

I send gamepad data over radio. This is low-level electronics (not a major existing game controller) and the framework only has a single receive event, so it's important to send all joystick state data in one packet, so it can be unpicked simultaneously.

I'm do this by combining multiple binary components into a single number:

  • The first 10 bits are x axis, 0-1023
  • The next 10 bits are y axis, 0-1023
  • The next 4 bits are 4 buttons' state, each 0 or 1.

eg: 1111111111100000000001010 (bottom right, holding two buttons)

At radio level it's just a list of bits, but how I interpret it, into fixed length sections is the part I'm trying to explain.


Solution

  • Reading around tells me these are called bit fields.

    Interesting to see that Wikipedia's example includes code for a gaming controller. Suggests I'm probably on the right path with what I'm doing. It also suggests that C's Structs are themselves bit fields.