Bitwise and Conditional Operators
Learn about different bitwise and conditional operators in Solidity.
We'll cover the following
In this lesson, we’ll explore bitwise and conditional operators in Solidity. These operators offer specialized capabilities that allow us to work with individual bits and create conditional expressions with concise syntax. Additionally, we’ll explore the conditional operator, which provides an elegant method for making decisions.
Bitwise operators
These operators are used to carry out operations at the bit level. The following bitwise operators are supported by Solidity:
Bitwise AND (
&
): The boolean AND operation is applied to each bit of the integer input.Bitwise OR (
|
): The boolean OR operation is applied to each bit of the integer input.Bitwise XOR (
^
): The boolean exclusive OR (XOR) operation is applied to each bit of the integer input.Bitwise Not (
~
): The boolean NOT operation is applied to each bit of the integer input.Left shift (
<<
): The first operand’s bits are all moved to the left by the number of positions given by the second operand.Right shift (
>>
): The first operand’s bits are all moved to the right by the number of positions indicated by the second operand.
Here’s a code example that demonstrates the use of bitwise operators in Solidity:
Get hands-on with 1400+ tech skills courses.