Hello @jhsa ,
I was a bit fiddler in my heyday!
void setup()
{
for(int i=0; i<16; i++)
{
print(bitRead(0xAA55, i));
}
println();
println(binary(0xAA55, 16));
println();
int bTest = 0xFF00;
println(binary(bTest, 16));
bTest = bitSet(bTest, 1);
println(binary(bTest, 16));
bTest = bitClear(bTest, 14);
println(binary(bTest, 16));
}
int bitRead(int b, int bitPos)
{
int x = b & (1 << bitPos);
return x == 0 ? 0 : 1;
}
int bitSet(int b, int bitPos)
{
int x = b | (1 << bitPos);
return x;
}
int bitClear(int b, int bitPos)
{
int x = b & ~(1 << bitPos);
return x;
}
It may need some testing and tweaking! A bit late for me to be coding.
:)