Skip to content

Main content

Bitwise: Bitmask Singleton Index Check Tool

Recognize a one-hot fixed-width mask and return its zero-based set-bit index, using -1 for zero or multiple set bits.

Loading tool…

Description

Return a singleton mask's bit index or a sentinel.

Bit positions are usually counted from the least-significant bit, while a displayed binary string has its own left-to-right indexing convention. Masks, fields and parity predicates describe a selected region or pattern; local agreement does not validate a complete encoded record.

Return a singleton mask's bit index or a sentinel.

When to use this tool

Use Bitwise: Bitmask Singleton Index Check when checking the stated mask, field, parity or bit-index convention.

How to use the tool and how it works

  1. Enter mask, width. 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 result. Expand result to inspect the returned fields.

Return a singleton mask's bit index or a sentinel. Validate bounded mask; singleton means nonzero with mask AND (mask-1) zero, index is its set-bit position or -1 otherwise.1

Input fieldMeaning and unitsAccepted input
maskMaskRequired. Text. Integer syntax: optional + or - and 1-128 decimal digits; leading zeros accepted. Apply the sign restriction above. Implementation limit: 8192 Unicode code points and 16384 UTF-16 code units. Word value must satisfy 0 <= value < 2^width.
widthWidth under the stated bit, interval or geometry convention; apply the field-specific units and bounds.Required. Safe integer. Fixed-word implementation domain: whole width 1-128 bits.
Output fieldInterpretationReturned shape
resultReturned calculated value or nested object under the stated output convention.Required. Object.
result.singletonSingletonCalculated result member: boolean.
result.indexZero-based singleton bit position from the least-significant end, or -1 when not singleton.Calculated result member: number.
json
{
  "input": {
    "mask": "8",
    "width": 8
  },
  "output": {
    "result": {
      "singleton": true,
      "index": 3
    }
  }
}

Limitations and assumptions

  • Zero and multi-bit masks are successful false results, not invalid inputs or index zero.
  • Outputs are nested inside result. 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 an explicit bit order, word width and missing-position policy; use the complete record format and appropriate parsing or checksum methods for full validation.

References

  1. Calculation and input contract: bitwise/bitmask-singleton-index-check — tool.io

Similar or alternative tools