You are here

Difference between Logical Negation and Bitwise complement | Cypress Semiconductor

Support & Community

Difference between Logical Negation and Bitwise complement

Last Updated: June 26, 2011

What is difference between logical negation and bitwise complement ?


Logical negation is represented as '!' and bitwise complement is represented as '~'. The logical negation evaluated over the entire Byte.  If the value is non-zero, then the logical negation results in zero.  Whereas, bitwise compliment compliments each bit in the byte.  Logical negation and bitwise compliment are completely different operations.  For example consider the following code snippet:

void main( void )


   BYTE A = 0x01;
   BYTE B = 0x02;

   // Define 2LEDs

   // Switch off all the LEDs

   // As the value of A is non-zero, a logical negation results in zero.
   // The expression evaluates as (0x00 & 0x02)=0x00 hence LED 1 is OFF
   if(!A & B)

   // Bitwise compliment of 0x01 results in 0xFE
   // The expression evaluates as (0xFE & 0x02)=0x02 hence LED 2 is ON.
   if(~A & B)


Knowledge Base Tags: 

Provide feedback on this article

Browse KB By Product

Browse KB by Type