bitfield.h File Reference

bitfields operations on bitfields of arbitrary length More...

Detailed Description

Note
Code taken mostly from Stackoverflow, User Christoph
Author
Oliver Hahm olive.nosp@m.r.ha.nosp@m.hm@in.nosp@m.ria..nosp@m.fr

Definition in file bitfield.h.

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
+ Include dependency graph for bitfield.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define BITFIELD(NAME, SIZE)   uint8_t NAME[((SIZE) + 7) / 8]
 Declare a bitfield of a given size. More...
 
static void bf_set (uint8_t field[], size_t idx)
 Set the bit to 1. More...
 
static void bf_unset (uint8_t field[], size_t idx)
 Clear the bit. More...
 
static void bf_toggle (uint8_t field[], size_t idx)
 Toggle the bit. More...
 
static bool bf_isset (uint8_t field[], size_t idx)
 Check if the bet is set. More...
 
int bf_get_unset (uint8_t field[], int size)
 Atomically get the number of an unset bit and set it. More...
 

Macro Definition Documentation

#define BITFIELD (   NAME,
  SIZE 
)    uint8_t NAME[((SIZE) + 7) / 8]
Note
SIZE should be a constant expression. This avoids variable length arrays.

Definition at line 42 of file bitfield.h.

Function Documentation

int bf_get_unset ( uint8_t  field[],
int  size 
)

This function can be used to record e.g., empty entries in an array.

Parameters
[in,out]fieldThe bitfield
[in]sizeThe size of the bitfield
Returns
number of bit that was set
-1 if no bit was unset
static bool bf_isset ( uint8_t  field[],
size_t  idx 
)
inlinestatic
Parameters
[in,out]fieldThe bitfield
[in]idxThe number of the bit to check

Definition at line 83 of file bitfield.h.

static void bf_set ( uint8_t  field[],
size_t  idx 
)
inlinestatic
Parameters
[in,out]fieldThe bitfield
[in]idxThe number of the bit to set

Definition at line 50 of file bitfield.h.

static void bf_toggle ( uint8_t  field[],
size_t  idx 
)
inlinestatic
Parameters
[in,out]fieldThe bitfield
[in]idxThe number of the bit to toggle

Definition at line 72 of file bitfield.h.

static void bf_unset ( uint8_t  field[],
size_t  idx 
)
inlinestatic
Parameters
[in,out]fieldThe bitfield
[in]idxThe number of the bit to clear

Definition at line 61 of file bitfield.h.