User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Enter a binary, decimal, or hex value
Presets:
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

A right bit-shift displaces every bit in a binary word toward the least-significant position by n places. The n least-significant bits are discarded. What fills the vacated most-significant positions determines the shift type: a logical shift inserts 0s, while an arithmetic shift replicates the original sign bit. Confusing the two produces silently wrong results in signed arithmetic. Dividing a signed negative integer with a logical shift instead of an arithmetic one yields a large positive number rather than the expected negative quotient. This tool performs both shift variants across 8, 16, 32, and 64-bit widths with full two's complement representation, so you can verify firmware masks, protocol headers, or compiler output without risking a subtle off-by-one in production code.

Input accepts binary, decimal, or hexadecimal notation. The bit-level visualization color-codes retained, dropped, and filled positions so the mechanical effect of the shift is immediately visible. Note: results assume a fixed-width register. Overflow and sign extension behave exactly as they would in a hardware ALU of the selected width.

binary right shift bit shift calculator bitwise operations logical shift arithmetic shift binary calculator bit manipulation

Formulas

The logical right shift by n positions on a w-bit unsigned value:

result = value2n = floor(value ร— 2โˆ’n)

The arithmetic right shift preserves the sign bit s. For a w-bit two's complement integer:

result = (value >> n) | (mask)

where the fill mask is:

mask =
{
0 if s = 0 (positive)((2n โˆ’ 1) << (w โˆ’ n)) if s = 1 (negative)

Where value is the input integer, n is the shift amount (0 โ‰ค n โ‰ค w), w is the register width in bits, and s is the most-significant bit (sign bit) of the original value. Arithmetic right-shift of a negative number rounds toward negative infinity, not toward zero.

Reference Data

Shift Amount8-bit Logical (unsigned 200)8-bit Arithmetic (signed โˆ’56)Equivalent DivisionBits Dropped
011001000 โ†’ 20011001000 โ†’ โˆ’56รท 10
101100100 โ†’ 10011100100 โ†’ โˆ’28รท 21
200110010 โ†’ 5011110010 โ†’ โˆ’14รท 42
300011001 โ†’ 2511111001 โ†’ โˆ’7รท 83
400001100 โ†’ 1211111100 โ†’ โˆ’4รท 164
500000110 โ†’ 611111110 โ†’ โˆ’2รท 325
600000011 โ†’ 311111111 โ†’ โˆ’1รท 646
700000001 โ†’ 111111111 โ†’ โˆ’1รท 1287
800000000 โ†’ 011111111 โ†’ โˆ’1รท 2568

Frequently Asked Questions

A logical right shift (often denoted >>> in languages like Java and JavaScript) always fills vacated most-significant bits with 0. It treats the operand as unsigned. An arithmetic right shift (>>) copies the original sign bit into the vacated positions. For positive numbers both produce identical results. For negative numbers in two's complement, arithmetic shift preserves the sign (result stays negative), while logical shift produces a large positive value. Example: 11110000 (signed โˆ’16 in 8-bit) shifted right by 1: arithmetic gives 11111000 (โˆ’8), logical gives 01111000 (120).
Arithmetic right shift by n is equivalent to floor division by 2n. For โˆ’7 >> 1, the mathematical result is โˆ’3.5, which floors to โˆ’4, not โˆ’3. This is a known asymmetry with integer division in C and most hardware ALUs. If your code expects truncation toward zero, you need to add a correction term: result = (x + ((x >> (w โˆ’ 1)) & ((1 << n) โˆ’ 1))) >> n.
For a logical right shift, shifting by w or more positions on a w-bit register always yields 0 because every original bit is discarded and replaced with 0. For an arithmetic right shift on a negative value, the result becomes all 1s (which is โˆ’1 in two's complement). In C, shifting by an amount โ‰ฅ the type width is technically undefined behavior. This tool clamps the shift to the selected bit width to give you the mathematically consistent result.
Two's complement encodes negative numbers by inverting all bits and adding 1. The MSB serves as the sign bit: 0 for non-negative, 1 for negative. When you select an 8-bit width and enter decimal 200, the tool treats it as unsigned 11001000. The same bit pattern read as signed 8-bit is โˆ’56. The shift operation acts on the raw bits identically; interpretation differs based on signed vs unsigned context. This is why the tool shows both interpretations.
Yes, for unsigned or known-positive values: x >> n is equivalent to floor(x รท 2n). Modern compilers already optimize integer division by powers of two into shifts, so the performance benefit in high-level languages is negligible. The risk emerges with signed negatives: โˆ’7 รท 2 truncates to โˆ’3 in most languages, but โˆ’7 >> 1 floors to โˆ’4. If your values can be negative, prefer explicit division for clarity.
JavaScript's native bitwise operators (>>, >>>) coerce operands to 32-bit integers, losing precision for larger values. This tool uses BigInt arithmetic internally, which handles arbitrary-precision integers. The 64-bit mode accurately models CPU registers (x86-64, ARM64) and data types like C's int64_t or Java's long without JavaScript's 32-bit truncation artifacts.