blob: 04b80be8de281dafece1ed15478d5d727c3e1bee [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 string clear_bit(string str, int n)
MG Mud User88f12472016-06-24 23:31:02 +02003
Zesstra715ec202025-07-09 22:18:31 +02004DESCRIPTION
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 User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008 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 User88f12472016-06-24 23:31:02 +020013
Zesstra715ec202025-07-09 22:18:31 +020014EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020015 string s;
Zesstra715ec202025-07-09 22:18:31 +020016 s=clear_bit("_",5);
MG Mud User88f12472016-06-24 23:31:02 +020017
Zesstra715ec202025-07-09 22:18:31 +020018 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 User88f12472016-06-24 23:31:02 +020021
22 string s;
Zesstra715ec202025-07-09 22:18:31 +020023 s=clear_bit("?<",3);
24 s=clear_bit(s,8);
MG Mud User88f12472016-06-24 23:31:02 +020025
Zesstra715ec202025-07-09 22:18:31 +020026 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 User88f12472016-06-24 23:31:02 +020034
Zesstra715ec202025-07-09 22:18:31 +020035SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020036 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)