Bit Shift Calculator

Shift a number’s bits left or right and see the result in binary, hex, octal and decimal.

Updated

Shift direction
Enter to calculate Esc to clear

Bit Shift Calculator

Our Bit Shift Calculator moves a number’s binary digits left or right by any number of places, exactly like the <<, >> and >>> operators in most programming languages. Type the number in decimal, binary, octal or hex, choose a bit width from 1 to 64, and see the result in every format, with a bit diagram showing which bits fell off and which were filled in.

Quick answer

A bit shift slides every bit of a number a set number of places. Shifting left by s multiplies by 2s, so 10 << 2 = 40, and shifting right by s divides by 2s and rounds down, so 40 >> 2 = 10. Enter any number above and the calculator shows the shifted result instantly.

  • Left shift (<<): bits move left, zeros fill in on the right
  • Arithmetic right shift (>>): copies the sign bit in on the left, so −8 >> 1 = −4
  • Logical right shift (>>>): fills with zeros, so in 8 bits −8 >>> 1 = 124
  • Overflow: bits pushed past the bit width are lost, so in 8 bits 200 << 1 = 144

What Is a Bit Shift?

A bit shift takes a number’s binary representation and slides every bit a fixed number of places to the left or right. Bits that move past either end are discarded, and the places left empty are filled in. A left shift fills with zeros and doubles the number for every place moved. A right shift halves it for every place moved, and there are two ways to fill the empty places on the left: an arithmetic shift repeats the sign bit, which keeps negative numbers negative, while a logical shift always fills with zeros.

Computers work with a fixed number of bits, called the bit width (8 bits for a byte, 32 for a typical int, 64 for a long). The width decides which bits fall off and which bit is the sign bit, so the same shift can give different answers at different widths.

Bit Shift Formulas

Left shift: n << s = n × 2^s, wrapped to the bit width
Arithmetic right shift: n >> s = floor(n ÷ 2^s)
Logical right shift: n >>> s = floor(u ÷ 2^s), where u is n read as unsigned

Here n is the number and s is the shift amount. In a w-bit width, “wrapped” means only the lowest w bits are kept, which is the same as taking the remainder after dividing by 2w. A negative number is stored in two’s complement, so −8 in 8 bits is 11111000, which reads as 248 when treated as unsigned (256 − 8).

Arithmetic vs Logical Right Shift

The two right shifts only differ when the sign bit (the leftmost bit) is 1. Here is the 8-bit pattern for −8 shifted right by one place each way:

ShiftBitsSignedUnsigned
Start (−8)1111 1000−8248
Arithmetic, −8 >> 11111 1100−4252
Logical, −8 >>> 10111 1100124124

Use an arithmetic shift for signed numbers (it divides by 2 and rounds down) and a logical shift for raw bit patterns, unsigned numbers and masks.

Example Calculations

10 << 2 (8-bit): 0000 1010 → 0010 1000 = 40 (10 × 2² = 40)
200 << 1 (8-bit): 1100 1000 → 1001 0000 = 144 (400 is too big, 400 − 256 = 144)
−8 >> 1 (8-bit): 1111 1000 → 1111 1100 = −4 (floor(−8 ÷ 2) = −4)
−8 >>> 1 (8-bit): 1111 1000 → 0111 1100 = 124 (zero-filled)
0xFF >>> 4 (8-bit): 1111 1111 → 0000 1111 = 0x0F (255 ÷ 16 = 15, rounded down)
1 << 10 (16-bit): = 1,024 (2¹⁰)

Notice the 0xFF line: as an 8-bit signed number 0xFF is −1, so an arithmetic shift would keep it at 1111 1111 (−1). Only the logical shift gives 15.

Shift Operators in Programming Languages

LanguageLeftRight on signed valuesLogical right
C / C++<<>> (arithmetic on mainstream compilers, guaranteed since C++20)>> on unsigned types
Java<<>> (arithmetic)>>>
JavaScript<<>> (arithmetic, 32-bit)>>> (unsigned 32-bit result)
C#<<>> (arithmetic)>>> (C# 11+), or >> on unsigned types
Python<<>> (arithmetic, no fixed width)none: mask first, e.g. (x & 0xFF) >> s
Go<<>> (arithmetic)>> on unsigned types

Python integers have no fixed width, so a left shift never overflows there: 1 << 100 is an exact 31-digit number. To match a fixed width, mask the result, for example (x << s) & 0xFF for 8 bits. For more bit operations, see the Bitwise Calculator.

Key Terms

Bit
A single binary digit, 0 or 1.
Bit width
How many bits a number is stored in, such as 8, 16, 32 or 64.
Sign bit
The leftmost bit. In signed numbers, 1 means negative.
Two’s complement
The usual way to store negative numbers: −n in w bits is stored as 2w − n.
Overflow
When a left shift pushes 1 bits past the top of the bit width, so the result wraps around.
Bit mask
A pattern such as 1 << n used to set, clear or test particular bits.

How to Use the Bit Shift Calculator

  1. Enter the number. Type the number in the “Number” box. Pick Dec, Bin, Oct or Hex for its format, or type a 0b, 0o or 0x prefix and the format switches by itself. Decimal numbers can be negative.
  2. Enter the shift amount. Type how many places to shift in the “Shift by (bits)” box, for example 2. Pressing Enter in the Number box moves you there.
  3. Choose the direction and bit width. Pick << Left, >> Arithmetic (right shift that copies the sign bit) or >>> Logical (right shift that fills with zeros). Set the bit width with the 8, 16, 32 or 64 chips, or type any width from 1 to 64.
  4. Read the result. The result appears as soon as the boxes are filled, in the same format as your number, with the working underneath (for example 10 << 2 = 40, 10 × 2² = 40). Below it, a bit diagram shows which bits fell off and which were filled in, and a table gives the result in binary, hexadecimal, octal, unsigned and signed decimal.
  5. Copy the result. Press Copy to copy the result without the spaces between digit groups. Press Clear or Esc to start again.

Example: enter −8, shift by 1, pick >> Arithmetic and an 8-bit width, and the result is −4, with the bits 1111 1000 becoming 1111 1100.

Who Can Use This Calculator?

ProgrammersChecking bitwise logic, masks and flags before they go into code
Computer Science StudentsBinary arithmetic, two’s complement and digital logic coursework
Embedded and Systems EngineersRegister fields, packed data and protocol bit layouts
Puzzle and CTF SolversQuick binary and hex shifts without writing a script

Frequently Asked Questions (FAQs)

What is a bit shift?

A bit shift moves every bit of a binary number a fixed number of places to the left or right. Bits pushed past the end are thrown away and the empty places are filled in. For example, shifting 00001010 (10) left by 2 gives 00101000 (40).

Does a left shift multiply by 2?

Yes. Each place a number is shifted left doubles it, so n << s = n × 2s, as long as no 1 bits are pushed off the top. 5 << 3 = 5 × 8 = 40. If the result is too big for the bit width it wraps around: in 8 bits, 200 << 1 gives 144 (400 − 256), not 400.

What is the difference between an arithmetic and a logical right shift?

Both move the bits right; they differ in what fills the empty places on the left. An arithmetic shift (>>) copies the sign bit, so negative numbers stay negative: in 8 bits, −8 >> 1 = −4 (11111000 becomes 11111100). A logical shift (>>>) always fills with zeros, so the same bits give 124 (01111100). For positive numbers the two give the same answer.

What does >>> mean?

>>> is the logical (unsigned, zero-fill) right shift operator in Java, JavaScript and C# 11 or later. It treats the number as unsigned and fills the left side with zeros. In JavaScript, −1 >>> 0 gives 4294967295, the unsigned 32-bit reading of all ones. C, C++, Python and Go have no >>> operator: shifting an unsigned type with >> does the same job.

Why is −5 >> 1 equal to −3 and not −2?

An arithmetic right shift divides by 2s and rounds down (towards minus infinity), so −5 >> 1 = floor(−2.5) = −3. Integer division in C, Java and JavaScript (with Math.trunc) rounds towards zero instead, giving −5 ÷ 2 = −2. For positive numbers the two agree: 13 >> 1 = 6.

What happens if you shift by the bit width or more?

Mathematically, every bit is shifted out: a left or logical right shift gives 0, and an arithmetic right shift gives 0 for positive numbers and −1 for negative ones. That is what this calculator shows. Programming languages differ: in C and C++ it is undefined behaviour, Java, JavaScript and C# only use the low 5 bits of the amount for 32-bit values (so x << 32 is x), and Go and Python give the mathematical answer.

What is 1 << n used for?

1 << n is 2n, a number with only bit n set: 1 << 10 = 1,024. Programmers use it to build bit masks and flags, for example x | (1 << 3) sets bit 3 and x & (1 << 3) tests it. (1 << n) − 1 gives n ones in a row, such as 255 for n = 8.

Why does the bit width matter?

The width decides how many bits the number has, which bits fall off the top in a left shift and which bit is the sign bit. 10 << 4 is 160 in 16 bits, but in 8 bits the same pattern 10100000 reads as −96 when signed. Match the width to your data type: 8 for a byte, 16 for a short, 32 for an int and 64 for a long.

Is the Bit Shift Calculator free?

Yes. It is completely free, needs no sign-up, and can be used as many times as you like.

Try our Bit Shift Calculator to shift any number’s bits and see the result instantly.