Invert GMLscripts.com

bitwise_ror

bitwise rotate right

Returns the given value with its bits rotated to the right. Each bit value shifts its position right a number of places given by the count parameter. As each bit shifts beyond the least significant bit position, it is inserted into the most significant bit position. The most significant bit is determined by the size parameter.

bits = 58311;                    //  58311 [ 1110001111000111 ]
ror = bitwise_ror(bits, 1, 16);  //  61923 [ 1111000111100011 ]
ror = bitwise_ror(bits, 2, 16);  //  63729 [ 1111100011110001 ]
ror = bitwise_ror(bits, 3, 16);  //  64632 [ 1111110001111000 ]
ror = bitwise_ror(bits, 4, 16);  //  32316 [ 0111111000111100 ]

NOTE: If the given integer is larger than the given size, the excess upper bits will be cleared.

bitwise_ror(n, count, size)
Returns the given integer rotated right a number of bit positions.
COPY/// @func   bitwise_ror(n, count, size)
///
/// @desc   Returns the given integer rotated right 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_ror(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