Category

Bit Shift Calculator — Left & Right Logical Shift in Binary, Decimal, Octal & Hex | 8, 16, 32, 64-Bit

Shift binary numbers left or right by any number of positions. Accepts decimal, binary, and octal input. Results shown in binary, decimal (signed & unsigned), octal, and hexadecimal for 8, 16, 32, and 64-bit representations.

0 calculations

Calculation Parameters

bits

Enter Parameters

Fill in the form on the left and click "Calculate"

What Is a Bit Shift?

A bit shift is a fundamental bitwise operation performed on a binary number. Binary numbers use base-2, meaning every digit is either 0 or 1 — the smallest unit of digital information called a bit. When you shift a binary number, every bit moves left or right by a specified number of positions.

The Bit Shift Calculator supports input in decimal, binary, and octal number systems, and shows results in all formats including hexadecimal — for both signed (two's complement) and unsigned representations across 8-bit, 16-bit, 32-bit, and 64-bit sizes.

Left Shift vs. Right Shift

There are two directions for a logical bit shift:

  • Left shift (≪) — moves all bits toward the most significant side. Zeros fill in from the right. Bits shifted past the boundary are discarded. Shifting left by n positions is equivalent to multiplying by 2n.
  • Right shift (≫) — moves all bits toward the least significant side. Zeros fill in from the left (logical shift). Bits shifted out on the right are discarded. Shifting right by n positions is equivalent to integer division by 2n (floor division).

Example: Left Shift by 2

Take the decimal number 21, which is 0001 0101 in 8-bit binary. Shifting left by 2:

Input (decimal)21
Input (binary, 8-bit)0001 0101
After left shift ≪ 20101 0100
Result (decimal)84 (= 21 × 4)

Example: Right Shift by 1

Take decimal 21 (0001 0101). Shifting right by 1:

Input (binary)0001 0101
After right shift ≫ 10000 1010
Result (decimal)10 (= ⌊21 ÷ 2⌋)

Signed vs. Unsigned Representation

When a binary number's most significant bit (MSB) is 1, it can represent a negative number in signed two's complement notation. The calculator shows both interpretations:

  • Unsigned: treats the bit pattern as a non-negative integer (0 to 2n−1)
  • Signed: interprets the MSB as a sign bit (−2n−1 to 2n−1−1)

For example, the 8-bit pattern 1111 0000 is 240 unsigned but −16 signed.

Bit Sizes and Byte Equivalents

Bit SizeBytesUnsigned RangeSigned Range
8 bits1 byte0 – 255−128 – 127
16 bits2 bytes0 – 65 535−32 768 – 32 767
32 bits4 bytes0 – 4 294 967 295−2 147 483 648 – 2 147 483 647
64 bits8 bytes0 – 18.4 × 1018−9.2 × 1018 – 9.2 × 1018

How to Use the Bit Shift Calculator

  1. Enter a number — type it in decimal (e.g., 21), binary (e.g., 10101), or octal (e.g., 25).
  2. Choose the input format — select Decimal, Binary, or Octal from the dropdown.
  3. Select bit size — pick 8, 16, 32, or 64 bits depending on your context.
  4. Choose direction — Left (≪) or Right (≫).
  5. Set shift amount — how many positions to move the bits (0 to bit_size−1).
  6. Click Calculate — results appear in binary, decimal (unsigned & signed), octal, and hexadecimal.

Practical Applications

  • Arithmetic shortcuts — shifting is faster than multiplication/division in low-level code
  • Cryptography — used in hash functions, ciphers, and LFSR algorithms
  • Graphics & image processing — pixel color channel extraction with masks and shifts
  • Networking — IP subnet mask calculations and flag bit manipulation
  • Embedded systems & registers — reading and writing hardware control registers
  • Compression algorithms — Huffman coding and other entropy-coding techniques

Frequently Asked Questions

What is the difference between logical and arithmetic right shift?

A logical right shift always fills vacated bits with zeros, treating the number as unsigned. An arithmetic right shift fills vacated bits with the original sign bit, preserving the sign in two's complement. This calculator performs a logical right shift, consistent with unsigned interpretation.

What happens when bits "fall off" the edge?

Bits shifted beyond the bit-size boundary are permanently lost. On a left shift this is called overflow. The calculator notes when the mathematical result (×2n) exceeds the bit-size capacity.

Can I shift by zero positions?

Yes — a shift of 0 returns the original number unchanged, which is useful for testing the calculator or as a no-op in code.

Is shifting by the full bit size (e.g., 8 on an 8-bit number) valid?

The maximum shift amount is bit_size − 1. Shifting by the full width would always produce zero and is undefined behavior in some languages (e.g., C/C++). This calculator clamps the shift amount to a safe range.

How are negative numbers handled?

Negative decimal inputs are converted to their unsigned two's complement representation within the selected bit size before shifting. For example, −1 in 8-bit becomes 1111 1111 (255 unsigned).

Calculation History

Loading...