This is an old revision of the document!
Bitwise operations library contains a set of macro functions to do common bit manipulation operations. They are used by the rest of the library and they can be used everythere else. As the macro functions have no type, they are compatible with any data type.
Bit index is used to specify the bit in the binary number. Indexes are counted from zero, where zero represents the least significant bit (LSB). For example, 8-bit number have 8 bits with indexes from 0 to 7 and 16-bit number have 16 bits with indexes from 0 to 15.
Bit index to bit mask converting. Parameters:
Sets a specified bit in the variable. Parameters:
Clears a specified bit in the variable. Parameters:
Set a specified bit in the variable to desired state. Parameters:
Inverts a specified bit in the variable. Parameters:
Checks whether a specified bit in the variable is set or not. Parameters:
Checks whether a specified bit in the variable is cleared or not. Parameters:
Setting up a third bit in the 8-bit variable b and inverting of the last one.
#include <homelab/bit.h> int main(void) { unsigned char b = 0x00; bit_set(b, 2); bit_invert(b, 7); }