- Documentation
- Shared functions
- bitReplace
Function
bitReplace
Writes replace into count bits starting at start, leaving the other bits unchanged.
Syntax
int bitReplace(int value, int replace, int start [, int count = 1])Arguments
valueint- The number.
replaceint- The value to insert.
startint- Position of the first bit.
countint, optional = 1- Number of bits.
Returns
The result or false.
Example
Packing three numbers into one.
local packed = 0
packed = bitReplace(packed, 12, 0, 8) -- poziom / level
packed = bitReplace(packed, 3, 8, 4) -- ranga / rank
packed = bitReplace(packed, 1, 12, 1) -- vip
print(bitExtract(packed, 8, 4)) -- 3