# JavaScript: Bitwise Operators

## Bitwise Operators

Bitwise operators perform an operation on the bitwise (0,1) representation of their arguments, rather than as decimal, hexadecimal, or octal numbers. For example, the decimal number eight has a binary representation of 1000. Bitwise operators do their operations on such binary representation (for example 1000) but they return standard JavaScript numerical values.

Here is a list of JavaScript's bitwise operators.

Operator |
Usage |
Description |
---|---|---|

Bitwise AND | a & b | Returns a one in each bit position if bits of both left and right operands are ones. |

Bitwise OR | a | b | Returns a one in each bit if bits of either left or right operand is one. |

Bitwise XOR | a ^ b | Returns a one in a bit position if bits of one but not both left and right operand are one. |

Bitwise NOT | ~ a | Flips the bits of its operand. |

Left shift | a << b | Shifts a in binary representation b bits to the left, shifting in zeros from the right. |

Sign-propagating right shift | a >> b | Shifts a in binary representation b bits to the right, discarding bits shifted off. |

Zero-fill right shift | a >>> b | Shifts a in binary representation b bits to the right, discarding bits shifted off, and shifting in zeros from the left. |

## Want to Test your JavaScript skill ?

## Want to Practice JavaScript exercises ?

- JavaScript basic [ 13 Exercises with Solution ]
- JavaScript functions [ 21 Exercises with Solution ]
- JavaScript conditional statements and loops [ 10 Exercises with Solution ]
- JavaScript array [ 13 Exercise with Solution ]
- JavaScript regular expression [ 6 Exercises with Solution ]
- JavaScript HTML DOM [ 14 Exercises with Solution ]
- JavaScript Drawing [ 5 Exercises with Solution ]
- JavaScript Object [ 4 Exercises with Solution ]

**Previous: ** JavaScript: Assignment Operators

**Next:** JavaScript: Comparison Operators

Test your Programming skills with w3resource's quiz.

## JavaScript: Tips of the Day

**Sort Number Arrays**

JavaScript arrays come with a built-in sort method. This sort method converts the array elements into strings and performs a lexicographical sort on it by default. This can cause issues when sorting number arrays. Hence here is a simple solution to overcome this problem.

[0,10,4,9,123,54,1].sort((a,b) => a-b); >>> [0, 1, 4, 9, 10, 54, 123]

You are providing a function to compare two elements in the number array to the sort method. This function helps us the receive the correct output.

Ref: https://bit.ly/3adlwNy

**New Content published on w3resource:**- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework