I'm using the following code to clear a bit in position pos (starting with position 0 on the far right) in the integer value. (Please don't comment on the stupidity of the code writing right now). When I give it an input of 15 and 1 it gives me some massively negative number (-2147483639) as the return value while it should be returning 13
(clearing the first bit would effectively subtract two from the original value)
Any ideas on why this is not working properly?
Code:unsigned int IBCLR(int value, int pos) { unsigned int tempval = (unsigned)value; unsigned int temppos = (unsigned)pos; return tempval & (~((unsigned)1 << temppos)); }