I have an unsigned int
that holds a series of bits, and a certain bit location.
Now I want to set all bits to 1 from that bit location 'downwards'. How can this be achieved simply without a loop?
Example:
unsigned int bitloc=2;
unsigned int bits=??; //must become 0000 0111
unsigned int bitloc=4;
unsigned int bits=??; //must become 0001 1111
Equivalent function that creates the result:
bits=0;
for (unsigned int i=0; i<=bitloc; i++)
bits|=1<<i;