![]() The bitwise XOR operator is the most useful operator from a technical interview perspective.Note: In C++, this behavior is well-defined. Another thing is, NO shift operation is performed if additive-expression(operand that decides no of shifts) is 0. For example, 1 << 33 is undefined if integers are stored using 32 bits. Also, if the number is shifted more than the size of the integer, the behaviour is undefined. 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. Compute the integer absolute value (abs) without branching.Travelling Salesman Problem | Set 1 (Naive and Dynamic Programming).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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |