I am working on a project which outputs to an odd circuit and need to invert half the byte I am sending. So for example, if I am sending the number 100 as a byte, it comes out in the chip as 01100100, nice and easy. The problem is that I need it to be 10010100, i.e. the first nibble is inverted. This is because of how the outputs of the chip work.
I have playing with the ~ command doing something like:
int b = a & 0x0000000F;
This inverts the second nibble. I can also invert the whole thing with:
int b = a & 0x000000FF;
But I want to get the first nibble of the byte and
int b = a & 0x000000F0;
doesn't give me the answer I am after.
User contributions licensed under CC BY-SA 3.0