I want to reset the 31st bit (last bit, 0 to 31 range) of int32_t, only this case seems to fail. i.e., Output failed for the case when 'i' is 31, it's returning -1. What is the error and how do I resolve this?
#include <stdio.h>
#include <stdlib.h>
void Release(int ResetBit, int32_t *Val)
{
int32_t testBit = 1; /* XoR Bit */
if (ResetBit >= 0 && ResetBit < 32)
{
testBit = (testBit << ResetBit);
*Val ^= testBit;
}
else
{
perror("Max range is 0-31 only, failed! ");
//exit(1);
}
}
int main(int argc, char const *argv[])
{
int count = 0;
for (int i = 0; i < 32; i++)
{
int32_t MaxValue = 2147483647;
Release(i, &MaxValue);
printf("MaxValue = %d NodeID = % d\n", MaxValue, i);
count++;
}
printf("%d", count);
return 0;
}
Output for the case i = 31 is:
MaxValue = -1 NodeID = 31