C is one of the most widely used programming languages of all time, and C compilers are available for the majority of available computer architectures and operating systems. And the reason behind its wide usage are some interesting facts that we will discuss here. We are going to discuss about two things:

  • Bitwise Operators
  • Macros And Preprocessors

Bitwise Operators in C

There are 6 types bitwise operators in C which will work at bit-level:

& (bitwise AND)  This operator will take two numbers as operand and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

| (bitwise OR)  This operator will take two numbers as operand and does OR on every bit of two numbers. The result of OR is 1 any of the two bits is 1.

^ (bitwise XOR) This operator will take two numbers as operand and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different check this.

<< (left shift) This operator will take two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift.

>> (right shift) This operator will take two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.

~ (bitwise NOT) This operator will take one number and inverts all bits of it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here