SYNOPSIS

int next_bit( string str, int start)
int next_bit( string str, int start, int find_cleared)

DESCRIPTION

Return the number of the next bit in bitstring str after position start. Usually this is the next set bit, but if find_cleared is given and not 0, the position of the next cleared bit is returned.

Note that finding cleared bits after the last set bit is limited to the actual length of str.

Each character contains 6 bits. So you can store a value between 0 and 63 in one character (2^6=64). Starting character is the blank char: (U+00020 SPACE) which has the value 0. The first character in the string is the one with the lowest bits (0-5).

USAGE

The below will write 2 and 4:

string s;
int p;

s = set_bit("", 4); s = set_bit(s, 2);

for (p = -1; -1 != (p = next_bit(s, p); )
    write(p+"\n");