## Bitwise operation (AND, OR, XOR)

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

### AND

- Returns 1 if both bits are 1.
- 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

- Returns 1 if either of the two bits is 1.
- Returns 0 if both bits are 0.

```
1010
OR 1100
= 1110
```

Many programming languages use `|`

as an operator.

`or = x | y;`

### XOR

- Returns 1 if the two bits have different values.
- 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

- Insert 0 in the rightmost empty bit position.
- 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
```