I think I need a utility method like this:
public static short bitValue(int intNum, short pos)
{
short bitValue = 0;
//check pos bit (from right to left) in the intNum integer to see its value is 0 or 1
//And then update the bitValue for return
return bitValue;
}
I am doing research to learn how to do it now. If anyone of you guy have code in hand, please share with me. thanks
Just do a shift and mask:
That’s assuming you want a return value of 1 or 0, of course. If you want bit itself, still with the same value, you’ll need to change your return type to
intand use: