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 set_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 set in string str. Note |
| 6 | 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 in one character (2^6=64). Starting character |
| 10 | is the blank " " which has the value 0. The first charcter in |
| 11 | the string is the one with the lowest bits (0-5). |
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 | The new string will automatically be extended if needed. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 15 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | string s; |
| 17 | s=set_bit("?",5); |
| 18 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 19 | Because "?" has a value of 31 the variable s will now contain |
| 20 | the character "_" which is equal to 63 (31+2^5=63). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 21 | |
| 22 | string s; |
| 23 | s=set_bit("78",3); |
| 24 | s=set_bit(s,8); |
| 25 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 26 | s will now contain the string "?<". |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 28 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 29 | clear_bit(E), last_bit(E), next_bit(E), test_bit(E), count_bits(E), |
| 30 | and_bits(E), or_bits(E), xor_bits(E), invert_bits(E), copy_bits(E) |