# What operation is the algorithm performing? [closed]

unsigned int input = 0xC116D9B5709FED85 unsigned int output = 0
while (input > 0 )
{
if (( input mod 2) == 1)
{
output += 1
}
input = floor(input / 2)
}
return output


I understand how the algorithm is working and using mod to break the input and then counting the number of times input is modded by 2 where it resulted 1. Basically checking if the number is odd. My question in the first place is howcome we can even store a huge hex like the one in question in an unsigned int. Doesn't it exceed the size limit of unsigned int. Secondly, if someone can help me understand the question would help alot.

• help me understand the question help understand what is asked - or - help find an answer? Both might be easier if you help everyone read your code: if you can't comment it (because you don't know what it is supposed to do, as in somebody else's code), format it more conventionally, or have a tool do that for you and everyone else. – greybeard Oct 22 '17 at 2:28
• @greybeard well first of all it is question I am trying to solve for a practice test. My goal is to learn. This is exactly how the code was written and i wrote it here. If you don't want to help somebody else learn, there is no need to be rude. If you do not understand the code, then maybe you shouldn't be replying. Thnx. – Rahul Oct 22 '17 at 2:43
• Programming questions are off-topic here but on-topic on stackoverflow. – Yuval Filmus Oct 22 '17 at 7:16

The algorithms counts the number of $1$s in the binary expansion of the input. The code as written seems a little weird because it’s not a function that can be applied to an input, it’s being specifically applied to the defined number. I certainly couldn’t tell you why it’s being applied to that number without a lot more context.

• The code as written seems syntactically incorrect. – greybeard Oct 22 '17 at 8:22
• Thank you Stella! You are right about counting the 1s...And I went over it on a piece of paper to understand how. Actually, yes this code is syntactically incorrect and I will be optimizing it more to work with all kinds of input as well. Thank you Stella for your help :) – Rahul Oct 22 '17 at 14:27