
For example results of both 1 > -1 is undefined.
If the second operand(which decides the number of shifts) is a negative number, it results in undefined behaviour in C.
The left shift and right shift operators should not be used for negative numbers. Interesting facts about bitwise operators The ~ (bitwise NOT) in C or C++ takes one number and inverts all bits of it. The > (right shift) in C or C++ takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. The result of XOR is 1 if the two bits are different. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers.
The result of OR is 1 if any of the two bits is 1.
The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers.
The result of AND is 1 only if both bits are 1.
The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today. Take a step-up from those "Hello World" programs. Travelling Salesman Problem | Set 1 (Naive and Dynamic Programming). Compute the integer absolute value (abs) without branching. Left Shift and Right Shift Operators in C/C++. How to count set bits in a floating point number in C?. Write a one line C function to round floating point numbers. Count total unset bits in all the numbers from 1 to N. Count total set bits in all numbers from 1 to N | Set 3. Count total set bits in all numbers from 1 to n | Set 2. Count total set bits in all numbers from 1 to n. Count number of bits to be flipped to convert A to B. Count ‘d’ digit positive integers with 0 as a digit. Converting Decimal Number lying between 1 to 3999 to Roman Numerals. Converting Roman Numerals to Decimal lying between 1 to 3999. Check if a string can be obtained by rotating another string 2 places. Check if strings are rotations of each other or not | Set 2. A Program to check if strings are rotations of each other or not. Bitwise Hacks for Competitive Programming. Code to generate the map of India (with explanation). How to change the output of printf() in main() ?. ISRO CS Syllabus for Scientist/Engineer Exam. ISRO CS Original Papers and Official Keys.
GATE CS Original Papers and Official Keys.