transformUint32Bits function
Replaces specific bits in a 32-bit unsigned integer.
Bits are specified by:
shift- Bitmask left-shift (0,1, ..., 30, 31)bitmask- For example, 0xF for 4 bits.
Implementation
int transformUint32Bits(int uint32, int shift, int bitmask, int newValue) {
if (bitmask | newValue != bitmask) {
throw ArgumentError.value(newValue, "newValue", "too many bits");
}
return ((0xFFFFFFFF ^ (bitmask << shift)) & uint32) | (newValue << shift);
}