GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2022-08-09 01:05:09

XydenKonos
Member
Registered: 2022-08-09
Posts: 1

count_set_bits()

/// @func   count_set_bits()
///
/// @desc   Returns a count of how many bits in a number are set.
///
/// @param  {real}      integer        real, nondecimal, positive number
///
/// @return  {real}      Total count of bits set
///
/// GMLscripts.com/license
function count_set_bits(n)
{
    n = floor(abs(n));
    var _count = 0;
    while(n>0)
    {
        _count += n & 1;
        n = n>>1;
    }
   
    return _count;
}

Offline

Board footer

Powered by FluxBB