MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 2 | string clear_bit(string str, int n) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 3 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 4 | DESCRIPTION |
| 5 | Return the new string where bit n is cleared in string str. |
| 6 | Note that the old string str is not modified. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | Each character contains 6 bits. So you can store a value |
| 9 | between 0 and 63 ( 2^6=64) in one character. Starting |
| 10 | character is the blank character " " which has the value 0. |
| 11 | The first charcter in the string is the one with the lowest |
| 12 | bits (0-5). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 13 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 14 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 15 | string s; |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 16 | s=clear_bit("_",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 | Because "_" is the highest possible value (63), the variable s |
| 19 | will now contain the charcter "?" wich is equal to 31 |
| 20 | (63-2^5=31). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 21 | |
| 22 | string s; |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 23 | s=clear_bit("?<",3); |
| 24 | s=clear_bit(s,8); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 25 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 26 | s will now contain the string "78". "?" equals 31 and "<" |
| 27 | equals 28. Now "?<" is equal to 31+28<<6=31+1792=1823 which is |
| 28 | in binary notation (highest bit on the right side) |
| 29 | 11111000111. Now clearing the bit 3 and bit 8 (bit numbering |
| 30 | starts with zero) will result in 11101000011. The first 6 bits |
| 31 | are in decimal notation 23 and the next 6 are equal to 24. Now |
| 32 | the 23 is the character "7" and 24 is the "8". So the string s |
| 33 | contains "78". |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 34 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 35 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 36 | set_bit(E), next_bit(E), last_bit(E), test_bit(E), count_bits(E), |
| 37 | and_bits(E), or_bits(E), xor_bits(E), invert_bits(E), copy_bits(E) |