MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 2 | int next_bit (string str, int start) |
| 3 | int next_bit (string str, int start, int find_cleared) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 5 | DESCRIPTION |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 10 | Note that finding cleared bits after the last set bit is limited to |
| 11 | the actual length of <str>. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 12 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 13 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 18 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 19 | 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 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 27 | --> will write 2 and 4 |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 29 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 30 | 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) |