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.
Direction
Right-shift type
bits
n << 2 = 10101000 (0xA8)
- 1
Mask n to 8 bits
42 & (256 − 1) = 42 - 2
n × 2^2 (mod 2^8)
(42 × 4) mod 256 = 168A left shift by k is equivalent to multiplying by 2^k within the bit width.
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
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
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
TG we-Calculate Editorial Team. "Bit Shift Calculator (Left & Right Shift)." TG we-Calculate. 2026. https://we-calculate.com/calculator/bit-shift-calculator.
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
@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?
