blob: 56805aa2f15bb442becafc84bca6b9d6154fccc7 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 int next_bit (string str, int start)
3 int next_bit (string str, int start, int find_cleared)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Return the number of the next bit in bitstring <str> after position
7 <start>. Usually this is the next set bit, but if <find_cleared>
8 is given and not 0, the position of the next cleared bit is returned.
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 Note that finding cleared bits after the last set bit is limited to
11 the actual length of <str>.
MG Mud User88f12472016-06-24 23:31:02 +020012
Zesstra715ec202025-07-09 22:18:31 +020013 Each character contains 6 bits. So you can store a value
14 between 0 and 63 in one character (2^6=64). Starting character
15 is the blank " " which has the value 0. The first character in
16 the string is the one with the lowest bits (0-5).
MG Mud User88f12472016-06-24 23:31:02 +020017
Zesstra715ec202025-07-09 22:18:31 +020018EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020019 string s;
20 int p;
21
22 s = set_bit("", 4); s = set_bit(s, 2);
23
24 for (p = -1; -1 != (p = next_bit(s, p); )
25 write(p+"\n");
26
Zesstra715ec202025-07-09 22:18:31 +020027 --> will write 2 and 4
MG Mud User88f12472016-06-24 23:31:02 +020028
Zesstra715ec202025-07-09 22:18:31 +020029SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020030 set_bit(E), clear_bit(E), test_bit(E), last_bit(E), count_bits(E),
31 and_bits(E), or_bits(E), xor_bits(E), invert_bits(E), copy_bits(E)