# Bitwise Operation / Bit Shifts calculator / 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 |

## How to use this tool

- 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.

```
1010
AND 1100
= 1000
```

Many programming languages use `&`

as an operator.

`and = x & y;`

### OR (Logical disjunction)

If either of the two bits is 1, 1 is returned; if both are 0, 0 is returned.

```
1010
OR 1100
= 1110
```

Many programming languages use `|`

as an operator.

`or = x | y;`

### 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
XOR 1100
= 0110
```

Many programming languages use `^`

as an operator.

`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. The following is an example for a 4-bit register.

```
1111 LEFT-SHIFT 1
= 1110
```

Many programming languages use `<<`

as an operator.

`leftShift = x << 1;`

### 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.

Since arithmetic shift preserves the sign, the left-most vacant bit position has the same value as the most significant bit (sign bit). The following is an example for a 4-bit register.

```
1011 RIGHT-SHIFT 1
= 1101
0011 RIGHT-SHIFT 1
= 0001
```

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.

```
1011 RIGHT-SHIFT 1
= 0101
```

Many programming languages use `>>`

or `>>>`

as an operator. The following is an example for a JavaScript.

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