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 | string copy_bits(string src, string dest |
| 3 | [, int srcstart [, int deststart [, int copylen ]]]) |
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 | Copy the bitrange [<srcstart>..<srcstart>+<copylen>[ from |
| 7 | bitstring <src> and copy it into the bitstring <dest> starting |
| 8 | at <deststart>, overwriting the original bits at those positions. |
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 | The resulting combined string is returned, the input strings remain |
| 11 | unaffected. |
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 | If <srcstart> is not given, <src> is copied from the start. |
| 14 | If <srcstart> is negative, it is counted from one past the last set |
| 15 | bit in the string (ie. '-1' will index the last set bit). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 17 | If <deststart> is not given, <dest> will be overwritten from the start. |
| 18 | If <deststart> is negative, it is counted from one past the last set |
| 19 | bit in the string (ie. '-1' will index the last set bit). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 21 | If <copylen> is not given, it is assumed to be infinite, ie. the result |
| 22 | will consist of <dest> up to position <deststart>, followed by |
| 23 | the data copied from <src>. |
| 24 | If <copylen> is negative, the function will copy the abs(<copylen>) |
| 25 | bits _before_ <srcstart> in to the result. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 26 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 27 | None of the range limits can become negative. |
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 | EXAMPLES |
| 30 | copy_bits(src, dest, 10) === src[10..] |
| 31 | copy_bits(src, dest, 10, 5) === dest[0..4] + src[10..] |
| 32 | copy_bits(src, dest, 10, 5, 3) |
| 33 | === dest[0..4] + src[10..12] + dest[8..] |
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 | (The src[]/dest[] is just for explanatory purposes!) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 36 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 37 | HISTORY |
| 38 | Introduced in LDMud 3.3.166. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 40 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | clear_bit(E), set_bit(E), test_bit(E), next_bit(E), last_bit(E), |
| 42 | count_bits(E), or_bits(E), xor_bits(E), invert_bits(E), and_bits(E) |