BITPOS

Since 1.1.0Bitmaps

Syntax

BITPOS key bit [start [end [BYTE | BIT]]]
  • Flags: readonly
  • ACL categories: @bitmap, @read, @slow
  • Arity: -3

Returns the position of the first bit set to bit (0 or 1) in the string at key, or in a part of it. start and end are byte offsets, unless BIT is given.

Reply

  • The position, counted in bits from the start of the string.
  • -1 if no bit is set to 1, when looking for 1.
  • When looking for 0 in a string of only 1s, with no end given: the first bit past the string. A missing key gives 0 for bit 0 and -1 for bit 1.

Examples

> SETBIT one 3 1
(integer) 0
> BITPOS one 1
(integer) 3
> BITPOS one 0
(integer) 0
> BITPOS missing 1
(integer) -1