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

Microcontrollers and basic bit-level operations

Why it’s so important to know how it works? Well, if you’re making a software for microcontrollers you have to use it in many places in the code to for example manipulate table of processor registers. It also helps to make the program smaller, much faster and allows to perform neat tricks (this isn’t always … Read more