Outils pour utilisateurs

Outils du site


helloworld:algorithms:numbers

Pleins d'algorithmes sur les bits

Déterminer le nombre de bits levés dans un nombre

Code C : (dépendant de gcc)

__builtin_popcount(i);

Using the GNU Compiler Collection (GCC): Other Builtins Archive v10.0.0 du 25/10/2019

Code C# :

static public uint NumberOfSetBits(uint i)
{
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}

How to count the number of set bits in a 32-bit integer? Archive du 20/09/2008 le 25/10/2019

helloworld/algorithms/numbers.txt · Dernière modification : 2019/10/25 11:21 de root