Bitwise Operation / Bit Shifts calculator / Tool
Tool
Bitwise Operation
| Bin (2) | Hex (16) | Dec (10) | Oct (8) | |
|---|---|---|---|---|
| Value1 | ||||
| Value2 | ||||
| AND | 0 | 0 | 0 | 0 |
| OR | 0 | 0 | 0 | 0 |
| XOR | 0 | 0 | 0 | 0 |
Bit Shifts
| Bin (2) | Hex (16) | Dec (10) | Oct (8) | |
|---|---|---|---|---|
| Value | ||||
| Left shift | 0 | 0 | 0 | 0 |
| Right shift | 0 | 0 | 0 | 0 |
Number of bits to shift
How to use
This is a tool for computing bitwise operations (AND, OR, XOR) and bit shifts that runs in your browser, supporting binary, hexadecimal, decimal, and octal numbers.
- Enter a numerical value in any radix and the calculation will be performed automatically.
- Calculated without 32-bit sign.
Bitwise Operation (AND, OR, XOR)
- AND (Logical conjunction): If both of the two bits are 1, 1 is returned; if either of them is 0, 0 is returned.
- OR (Logical disjunction): If either of the two bits is 1, 1 is returned; if both are 0, 0 is returned.
- XOR (Exclusive or): Returns 1 if the two bits have different values, 0 if they have the same value (1 if only one is 1, 0 if both are 0 or both are 1).
1010
AND 1100
= 1000
1010
OR 1100
= 1110
1010
XOR 1100
= 0110
Many programming languages use &, |, ^ as an operator.
and = x & y;
or = x | y;
xor = x ^ y;
Bit Shift
Shifts each digit in a bitstring to the right or left.
Since bit shift is also an operation on a bitstring, it is a type of bit operation in the broadest sense. However, it is often distinguished from bitwise operations because it is not a bit-by-bit operation, but rather on the whole number.
- Left shift: The rightmost empty bit position is filled with 0, and the overflowing leftmost bit disappears.
- Right shift: There are two types of shifts: arithmetic shift (signed) and logical shift (unsigned). This tool supports only the latter, logical shift. In both cases, the overflowed rightmost bit disappears, but the way to fill the leftmost empty bit position is different.
- Arithmetic shift: preserves the sign, the left-most vacant bit position has the same value as the most significant bit (sign bit).
- Logical shift: simply shifts all bits, so the left-most empty bit position is 0.
The following is an example for a 4-bit register.
# Left shift
1111 LEFT-SHIFT 1
= 1110
# Right shift (Arithmetic shift)
1011 RIGHT-SHIFT 1
= 1101
0011 RIGHT-SHIFT 1
= 0001
# Right shift (Logical shift)
1011 RIGHT-SHIFT 1
= 0101
Many programming languages use <<, >>, >>> as an operator.
leftShift = x << 1;
rightShift = x >> 1; // Arithmetic shift
rightShift = x >>> 1; // Logical shift