====Pleins d'algorithmes sur les bits====
[[http://graphics.stanford.edu/~seander/bithacks.html|Bit Twiddling Hacks]] {{ :helloworld:algorithms:numbers:bit_twiddling_hacks_2019-10-25_11_12_41_.html |Archive du 04/02/2011 le 25/10/2019}}
=====Déterminer le nombre de bits levés dans un nombre=====
Code C : (dépendant de gcc)
__builtin_popcount(i);
[[https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html|Using the GNU Compiler Collection (GCC): Other Builtins]] {{ :helloworld:algorithms:numbers:using_the_gnu_compiler_collection_gcc_other_builtins_2019-10-25_11_12_49_.html |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;
}
[[http://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer|How to count the number of set bits in a 32-bit integer?]] {{ :helloworld:algorithms:numbers:algorithm_-_how_to_count_the_number_of_set_bits_in_a_32-bit_integer_-_stack_overflow_2019-10-25_11_12_59_.html |Archive du 20/09/2008 le 25/10/2019}}