-1

A struct I'm dealing with has a field defined as uint8_t. The spec also states that all multiple-byte fields are represented in host-endian format.

Bits 0:3 contain the information that I need (also an unsigned integer). Using plain C, how do I extract those 3 bits and convert it to a number type?

Vitor Py
  • 5,145
  • 4
  • 39
  • 62

1 Answers1

3

unit8_t a; unit8_t b;

a = input data;

b = a & 0x0F; // b contains a number from 0 to 15

Enrico Migliore
  • 201
  • 3
  • 9