bitwise_rol
Returns the given value with its bits rotated to the left. Each bit value shifts its position left a number of places given by the count parameter. As each bit shifts beyond the most significant bit position, it is inserted into the least significant bit position. The most significant bit is determined by the size parameter.
bits = 58311; // 58311 [ 1110001111000111 ]
rol = bitwise_rol(bits, 1, 16); // 51087 [ 1100011110001111 ]
rol = bitwise_rol(bits, 2, 16); // 36639 [ 1000111100011111 ]
rol = bitwise_rol(bits, 3, 16); // 7743 [ 0001111000111111 ]
rol = bitwise_rol(bits, 4, 16); // 15486 [ 0011110001111110 ]
NOTE: If the given integer is larger than the given size, the excess upper bits will be cleared.
- bitwise_rol(n, count, size)
- Returns the given integer rotated left a number of bit positions.
COPY/// @func bitwise_rol(n, count, size)
///
/// @desc Returns the given integer rotated left a number of bit positions.
/// Note: Bits beyond the given size are masked off.
///
/// @param {real} n integer to be rotated
/// @param {real} count bit positions to rotate
/// @param {real} size size of integer in bits
///
/// @return {real} rotated integer
///
/// GMLscripts.com/license
function bitwise_rol(n, count, size)
{
var mask = (1 << size) - 1;
n &= mask;
return (n << count) | (n >> (size - count)) & mask;
}
Contributors: EyeGuy, xot
GitHub: View · Commits · Blame · Raw