# Bitwise Operation / Bit Shifts calculator

• Calculate unsigned 32-bit.

Bitwise Ops.Bin (2)Hex (16)Dec (10)Oct (8)
Value1
Value2
AND0000
OR 0000
XOR0000
Bit ShiftsBin (2)Hex (16)Dec (10)Oct (8)
Value
Left shift0000
Right shift0000
Number of bits to shift:

## Bitwise operation (AND, OR, XOR)

1. Input two bit strings.
2. Perform logical operations for each bit at the same position.

### AND

1. Returns 1 if both bits are 1.
2. Returns 0 if either of the two bits is 0.
    1010
AND 1100
= 1000

Many programming languages use & as an operator.

and = x & y;

### OR

1. Returns 1 if either of the two bits is 1.
2. Returns 0 if both bits are 0.
   1010
OR 1100
= 1110

Many programming languages use | as an operator.

or = x | y;

### XOR

1. Returns 1 if the two bits have different values.
2. Returns 0 if the two bits have the same value.
    1010
XOR 1100
= 0110

Many programming languages use ^ as an operator.

xor = x ^ y;

## Bit shift

Move each digit of the bit string to the right or left.

### Left shift

1. Insert 0 in the rightmost empty bit position.
2. Remove the overflowing leftmost bit.

e.g. For 4-bit registers.

  1111 LEFT-SHIFT 1
= 1110

Many programming languages use << as an operator.

leftShift = x << 1;

### Right shift

There are arithmetic shift (signed) and logical shift (unsigned). This tool only supports logical shift.

In an arithmetic shift retains the sign, so the leftmost bit does not change.

e.g. For 4-bit registers.

  1011 RIGHT-SHIFT 1
= 1101

0011 RIGHT-SHIFT 1
= 0001

In a logical shift does not retain the sign, so put a 0 at the left end.

e.g. For 4-bit registers.

  1011 RIGHT-SHIFT 1
= 0101

Many programming languages use >> or >>> as an operator.

e.g. For JavaScript

rightShift = x >> 1;  // Arithmetic shift
rightShift = x >>> 1; // Logical shift