Bitwise operators

These operators are used to compare and operate on values according to certain rules.

and (&)

and takes two numbers of equal lengths and compares the bits of both. If both of these bits are 1, the result is 1. If any of the two numbers compared are 0, the result is a 0:

01100110 & 10011100 = 0000100

or (|)

or takes two numbers of equal lengths and compares the bits of both. If either of the two bits compared is 1 or both are 1, the result is 1. If neither bit is 1, then the result is 0.

00110011 | 11011001 = 11111011

 

xor (^)

xor takes two numbers of equal lengths and compares the bits of both. If the compared bits are different (i.e., 0 and 1), then the result is 1. Otherwise, the result is 0.

010110011 ^ 10101010 = 11110001

not (~)

not takes only one value and inverts its bits: 1 becomes 0, and 0 becomes 1.

~01100011 = 10011100

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.