in reply to Locating a specified number of contiguous 0 bits within a large bitstring efficiently.

You could do it fairly efficiently with a regex, giving 8 alternations which represent the 8 possible start positions within a byte. For example, matching 12 contiguous zeros might be done using something along the lines of
/ \x00 [\x00\x10\x20\x30..\xf0] | [\x00\\x01] [\x00\x20\x40\x60..\xe0] ... [\x00-\x7f] \x00 [\x00\x08\x10\x18..\xf8] /x
(That's approx off the top of my head. It probably includes errors and endian mistakes. You'd want to write a function that generates it automatically.)

Dave.

  • Comment on Re: Locating a specified number of contiguous 0 bits within a large bitstring efficiently.
  • Download Code

Replies are listed 'Best First'.
Re^2: Locating a specified number of contiguous 0 bits within a large bitstring efficiently.
by BrowserUk (Patriarch) on Jun 07, 2013 at 03:20 UTC

    Any thoughts on how to convert $-[0] byte position at which the match is found to a bit position?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I guess just see how many high bits are zero in the byte at position $-[0] ?

      Dave.