Bitwise Operator in C (Left shift, Right Shift and NOT) In C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

In C, there are also three bitwise shift operators that can be used to shift the bits of a number left or right:

  1. Left Shift (<<): The left shift operator shifts the bits of the first operand to the left by the number of positions specified by the second operand. This has the effect of multiplying the first operand by 2 raised to the power of the second operand.

Example: 5 ​1

Malformed citation << 2; // results in 20 (5 * 2^2) 2. Right Shift (>>): The right shift operator shifts the bits of the first operand to the right by the number of positions specified by the second operand. This has the effect of dividing the first operand by 2 raised to the power of the second operand. Example: 20 >>

​ 2; // results in 5 (20 / 2^2)

 

  1. NOT (~): The bitwise NOT operator inverts the bits of the operand. It is a unary operator and the result of the NOT operation will be invert of each bit of the operand.

Example: ~5; // results in -6

It is important to note that bitwise shift operators can be used with both integers and characters in C. It is also important to note that the shift operation can lead to undefined behavior if the shift amount is greater or equal than the size of the type of the left-hand side expression.

4. Operators

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?