I am trying to write a method in C that takes three integers: start, end and mask. If the mask is 1, all bits except the bits in the range from beginning to end are set to 0, and the bits in the range are 1. I am working on this part now:
for (int i = 0; i < (end - start + 1); i++)
{
if (mask == 1)
{
ret |= ret << 1;
ret |= ret | 1;
}
}...ret = ret << start;
(where "ret" is an unsigned int and just starts at 0 if the mask is 1 or ~ 0 if the mask is 0). However, I cannot figure out how to do it differently: masking the bit range as 0 and setting everything else to 1.
source
share