Skip to content

Main content

Signed Right Shift Discarded Bit Count

Apply an explicit 32-bit arithmetic right shift and count one bits removed from the low positions.

Loading tool…

Description

Arithmetic-shift a supplied signed 32-bit integer and count discarded one bits.

Fixed-width bit operations depend on signed representation, word width and shift direction. An arithmetic right shift propagates the sign bit, while discarded-one counts describe the original low bits rather than the number of shifted positions. JavaScript bitwise operations use 32-bit words even when ordinary numeric inputs have wider precision.

Arithmetic-shift a supplied signed 32-bit integer and count discarded one bits.

When to use this tool

Use Signed Right Shift Discarded Bit Count when you already have signedInt32, shiftCount and need to arithmetic-shift a supplied signed 32-bit integer and count discarded one bits.

How to use the tool and how it works

  1. Enter signedInt32, shiftCount. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read shiftedValue, discardedOneBits. Use the output convention below.

Require signedInt32 in [-2147483648,2147483647] and whole shift 0..31; mask the low shift-count bits of its unsigned representation and count set bits. Return signed >> shift and that count.1

Input fieldMeaning and unitsAccepted input
signedInt32Whole number in [-2147483648,2147483647].Required. Safe integer; minimum -2147483648; maximum 2147483647.
shiftCountWhole right-shift count 0..31.Required. Safe integer; minimum 0; maximum 31.
Output fieldInterpretationReturned shape
shiftedValueShifted ValueRequired. Safe integer.
discardedOneBitsCount of one bits among the original discarded low positions, not the count of shifted positions.Required. Safe integer.
json
{
  "input": {
    "signedInt32": 13,
    "shiftCount": 2
  },
  "output": {
    "shiftedValue": 3,
    "discardedOneBits": 1
  }
}

Limitations and assumptions

  • Zero shift discards nothing. Negative shifts sign-extend rather than zero-fill; discardedOneBits counts ones, not positions discarded. No arbitrary-width word or unsigned-shift convention is inferred.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Choose a complete word representation and verify the intended signedness before combining bit operations. Use a logical shift when zero filling is required and inspect the full bit pattern when a local shift result cannot answer the question.

References

  1. Calculation and input contract: bitwise/signed-right-shift-discarded-bit-count — tool.io

Similar or alternative tools

  • bitwise/right-shift

    Shift an integer's 32-bit form right by the given number of bits, preserving the sign.

  • bitwise/left-shift

    Shift an integer's 32-bit form left by the given number of bits.