⬆️ ⬇️

Is the code beautiful ???

int get_ones_count (int x)

{

x = (x & 0x55555555) + ((x & 0xAAAAAAAA) >> 1);

x = (x & 0x33333333) + ((x & 0xCCCCCCCC) >> 2);

x = (x & 0x0F0F0F0F) + ((x & 0xF0F0F0F0) >> 4);

x = (x & 0x00FF00FF) + ((x & 0xFF00FF00) >> 8);

x = (x & 0x0000FFFF) + ((x & 0xFFFF0000) >> 16);

return x;

}



Is this code beautiful? Why?



In general, it is interesting to read the thoughts on the topic beautiful / not beautiful code.

')

ps In my opinion, the code should be clear.



pps This code calculates the number of units in a binary number.

Source: https://habr.com/ru/post/24309/



All Articles