bit-level operations – check integer is even or odd

In this short article I will exaplain how to use bit-level operations to verify that integer is even or odd. It’s very useful and fast verification. Examples below have been compiled and tested using gnu-gcc. $/> gcc example.c -o example CHECK EVEN To verify that integer is even we need to check first bit is not set. #include <stdint.h> #include <assert.h> … Read more

Bit-level operations – bit flags and bit masks

This article introduces to bit flags, bit masks and basic bit-level operations on them. In the world of microcontrollers, when you need to save a boolean values (true/false) then it can be useful to “pack” individual boolean values into a single integer value for storage efficiency purposes. This is done by using the bitwise and shift operators to set, clear, … Read more