how to write an inverse() function in C programming only for lower 4 bits

Status
Not open for further replies.

Thread Starter

dezmond

Joined Sep 27, 2008
3
Anyone has any idea how to write the coding for an inverse() function in c programming which will only invert or toggle the 4 lower significant bits (a0~a3) and leave the 4 most significant bits (a4~a7) unchanged?

e.g.

porta = 0bx01010000;

and after the inverse function,

porta = inverse(porta);

so porta now is 0b01011111.

any one have any ideas? I've got a headache busting my brains out on this problem...
 

hgmjr

Joined Jan 28, 2005
9,029
Look into the Exclusive-Or operator "^". Just exclusive-or the binary value 0x00001111 with the byte in which you want to toggle the bits of the lower nibble.

hgmjr
 
Status
Not open for further replies.
Top