Course contentsShow
← JavaScript
Lesson 253 of 2,7237. Arithmetic and OperatorsFree lesson

What Are Bitwise Operators?

Learn how bitwise operators work directly on the binary representation of numbers in JavaScript.

What Are Bitwise Operators?

You'll learn what bitwise operators are and how they work directly on the binary representation of numbers in JavaScript.

The Core Idea

Bitwise operators are special operators that work at the lowest level of how computers store numbers: as sequences of 1s and 0s (binary). While most JavaScript operations treat numbers as decimal values (like 5, 10, or 42), bitwise operators convert them to their 32-bit binary form, perform operations on individual bits, then convert back to decimal.

Think of it like this: imagine each number as a row of light switches (on = 1, off = 0). Bitwise operators let you flip, compare, or combine these switches in specific patterns.

The Binary Connection

Every number in JavaScript can be represented as a binary pattern. For example:

  • The decimal number 5 is 101 in binary
  • The decimal number 3 is 011 in binary

Bitwise operators manipulate these underlying binary patterns directly, which is very different from regular arithmetic operators that work with decimal values.

Why They Exist

Bitwise operators are primarily used for:

  • Low-level programming tasks
  • Performance-critical operations
  • Working with binary flags or permissions
  • Certain algorithms that require bit manipulation

They're less common in everyday JavaScript than arithmetic or logical operators, but understanding them gives you insight into how computers actually process numbers.

Key Takeaway: Bitwise operators work on the binary (1s and 0s) representation of numbers, allowing you to manipulate individual bits within a 32-bit integer—a lower-level operation than typical arithmetic.