Invert GMLscripts.com

bitwise_reverse32

Returns the given 32-bit number with bits in reverse order.

bits = 123456789;               //   123456789 ( 00000111 01011011 11001101 00010101 )
rev = bitwise_reverse16(bits);  //  2830359264 ( 10101000 10110011 11011010 11100000 )
bitwise_reverse32(n)
Returns the given number with bits in reverse order.
COPY/// bitwise_reverse32(n)
//
//  Returns the given number with bits in reverse order.
//
//      n           32-bit integer, real
//
/// GMLscripts.com/license
{
    var n;
    n = argument0;
    n = (n & $55555555) <<  1 | (n & $AAAAAAAA) >>  1;
    n = (n & $33333333) <<  2 | (n & $CCCCCCCC) >>  2;
    n = (n & $0F0F0F0F) <<  4 | (n & $F0F0F0F0) >>  4;
    n = (n & $00FF00FF) <<  8 | (n & $FF00FF00) >>  8;
    n = (n & $0000FFFF) << 16 | (n & $FFFF0000) >> 16;
    return n;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw