Skip to content

Bit maps

Konstantin Khait edited this page Jul 22, 2026 · 1 revision

Bit maps (bit arrays) and bitwise operations helps managing the appropriate data being a supplimentary part of Loviisa OS.

Loviisa provides three types of mechanisms to work with bits:

  • Simple bitwise operations
  • Append'able ring buffers
  • Bit memory allocation

Basic type that represents a bit and can only have a value of 0 or 1:

// Single bit type
typedef char LVS_BIT_T;

Simple operations to get / set bit values in a bit array:

// Retrieve one bit
LVS_BIT_T lvs_BitmemGet1(unsigned char* mem, unsigned int index);
// Put one bit
void lvs_BitmemPut1(unsigned char* mem, unsigned int index, LVS_BIT_T bitval);
// Retrieve given number of bits
unsigned long long lvs_BitmemGet(unsigned char* mem, unsigned int index, unsigned char numbits);
// Put given number of bits
void lvs_BitmemPut(unsigned char* mem, unsigned int index, unsigned long long val, unsigned char numbits);

numbits must be not more than sizeof(unsigned long long) * 8, i.e. all bits shall be pack'able to unsigned long long value, LSB order is used, i.e. bit #0 is applied first.

Clone this wiki locally