Beginner

Bit Shift Calculator (Left & Right Shift)

Shift an integer left or right by a chosen number of bits and view the result in decimal, binary, and hexadecimal within a fixed bit width.
Decimal integer; negatives use two's complement in the bit width
Number of bit positions to shift

Direction

Right-shift type

Only applies to right shifts

bits

Result wraps to this many bits
Shifted value (decimal)
168

n << 2 = 10101000 (0xA8)

Binary (w-bit)
10101000
Hexadecimal
0xA8
Signed decimal
-88
Bits vacated/filled
2 (filled with 0)
Bits dropped
2 (0)
031.963.895.6127.5159.4191.3223.1255Value before and after shift in the 8-bit range
Step by step
  1. 1

    Mask n to 8 bits

    42 & (256 − 1) = 42
  2. 2

    n × 2^2 (mod 2^8)

    (42 × 4) mod 256 = 168
    A left shift by k is equivalent to multiplying by 2^k within the bit width.
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

A left shift moves bits toward the high end and fills zeros on the right; a right shift moves them toward the low end. Logical right shifts fill zeros on the left, while arithmetic right shifts copy the sign bit. Results are masked to the chosen bit width and shown in decimal, binary, and hex.

Formula
Left: r = (n << k) & mask; Logical right: r = (n & mask) >> k; Arithmetic right: sign bit replicated into the top k positions (mask = 2^w - 1)
How this is calculated

You provide an integer n, a shift amount k, a direction (left or right), the right-shift type (logical or arithmetic), and a bit width w. All arithmetic is done with arbitrary-precision integers and then constrained to w bits using mask = 2^w - 1. The input is first reduced to its w-bit pattern, so negative values are represented in two's complement.

A left shift computes (n << k) & mask: every bit moves k positions toward the most significant end, the low k positions are filled with zeros, and any bits that move past the top of the width overflow and are discarded. A logical right shift computes (n & mask) >> k: bits move k positions toward the least significant end, the low k bits are dropped, and the top k positions are filled with zeros. An arithmetic right shift behaves the same except the vacated top k positions are filled with copies of the original sign bit (the MSB), which preserves the sign of two's-complement numbers.

Results are shown as an unsigned decimal, a zero-padded w-bit binary string, and hexadecimal, plus the signed two's-complement interpretation. Shifting by k greater than or equal to w yields 0 for left and logical-right shifts, or an all-ones / all-zeros pattern for arithmetic-right shifts depending on the sign bit. Negative k is rejected.

Frequently asked questions

A logical right shift always fills the vacated high bits with zeros, treating the value as unsigned. An arithmetic right shift copies the sign bit (the most significant bit) into those positions, preserving the sign so that negative two's-complement numbers stay negative.

The result is masked to the chosen bit width. Bits shifted past the most significant position overflow and are dropped, so within a fixed width a left shift can wrap to a smaller value.

A negative n is converted to its w-bit two's-complement pattern before shifting. The output shows both the unsigned decimal and the signed decimal interpretation of that pattern.

Also known as

bit shift calculator
left shift right shift
logical shift
arithmetic shift
shift operator
bitwise shift
shift bits

APA

TG we-Calculate Editorial Team. (2026). Bit Shift Calculator (Left & Right Shift) [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/bit-shift-calculator

Chicago

TG we-Calculate Editorial Team. "Bit Shift Calculator (Left & Right Shift)." TG we-Calculate. 2026. https://we-calculate.com/calculator/bit-shift-calculator.

IEEE

TG we-Calculate Editorial Team, "Bit Shift Calculator (Left & Right Shift)," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/bit-shift-calculator

BibTeX

@misc{wecalculate_bit_shift_calculator, title = {Bit Shift Calculator (Left & Right Shift)}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/bit-shift-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?