bitShiftLeftTruncatingToBits

fun A_Number.bitShiftLeftTruncatingToBits(shiftFactor: A_Number, truncationBits: A_Number, canDestroy: Boolean): A_Number

Shift the non-negative integer to the left by the specified number of bits, then truncate the representation to force bits above the specified position to be zeroed. The shift factor may be negative, indicating a right shift by the corresponding positive amount, in which case truncation will still happen.

For example, shifting the binary number 1011₂ to the left by 2 positions will produce 101100₂, then truncating it to, say 5 bits, would produce 01100₂. For a second example, the positive number 110101₂ can be shifted left by -2 positions, which is a right shift of 2, to get 1101₂, and a subsequent truncation to 10 bits would leave it unaffected.

Return

(object × 2^shiftFactor) mod 2^truncationBits

Parameters

shiftFactor

How much to shift the receiver left (may be negative to indicate a right shift).

truncationBits

A positive integer indicating how many low-order bits of the shifted value should be preserved.

canDestroy

Whether it is permitted to alter the receiver if it happens to be mutable.