I have an array of bits (stored as Boolean) that I want to reconstruct into an integer. I want to insert bits from the right hand side and shift them left for every bit in my array.
How do I insert a bit at the LSB side and shift it over at the same time?
You would do something like this:
I’m assuming an int of size 32 here.
There are other considerations to take into account, like endianness but this should give you an idea. Also beware of signing issues, since in this case the highest (left-most) bit will affect whether the int comes out positive or negative.