Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
Bit-Field manipulation library

qlibs::bitfield class contains a setof functions for creating and manipulating bit fields also known as bit arrays. These are series of zeroes and ones spread across an array of storage units, such as unsigned long integers.

Structure

Bit arrays are stored in the qlibs::bitfield class. This class has two elements: an array of unsigned long integers called field for storing the bits and an integer size for storing the number of bits in the array.

Functions

Instance setup

Single-bit

Multiple-bits

Dump

Working with bitfields

#include <iostream>
#include <qlibs.h>
using namespace qlibs;
int main( int argc, char *argv[] )
{
bitfield vPort; // create the bitfield instance
bitArea<48> vPortArea; // Create the bitfield storage area to hold 48 bits
uint16_t rWord;
vPort.setup( vPortArea );
vPort.clearAll();
//we are going to write the following value in the bitfield = 0x8177AA55FF88
vPort.writeUINTn( 0, 0xAA55FF88, 32 ); // write the first 32 bits
vPort.writeUINTn( 32, 0x77, 8 ); // write one of the last two bytes
vPort.writeBit( 47, 1 ); // write the last bit of the last byte
vPort.writeBit( 40, 1 ); // write the first bit of the last byte
rWord = static_cast<uint16_t>( vPort.readUINTn( 20, 16 ); // read a word at offset 24
std::cout << std::hex << vPortArea[0] << ", "
<< vPortArea[1] << ", "
<< vPortArea[2] << ", "
<< vPortArea[3] << ", "
<< vPortArea[4] << ", "
<< vPortArea[5] << ", "
<< std::endl ;
return EXIT_SUCCESS;
}
A BitField object.
Definition bitfield.hpp:36
uint32_t readUINTn(const size_t index, const size_t xBits) const noexcept
Reads an unsigned 32-bit value from the BitField.
Definition bitfield.cpp:113
bool clearAll(void) noexcept
Clear all the bits in the BitField.
Definition bitfield.cpp:25
bool setup(void *const area, const size_t area_size) noexcept
Setup a initialize a BitField instance.
Definition bitfield.cpp:8
bool writeBit(const size_t index, const bool value) noexcept
Writes one bit in a bitfield.
Definition bitfield.cpp:95
bool writeUINTn(const size_t index, const size_t xBits, uint32_t value) noexcept
Writes an unsigned n-bit value from the BitField.
Definition bitfield.cpp:134
uint8_t[4U *(((N - 1U)/32U)+1U)] bitArea
Variable that allocates block of bytes to hold N bits for a BitField .
Definition bitfield.hpp:31
The qLibs++ library namespace.
Definition fp16.cpp:4