0
$\begingroup$
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.

$\endgroup$

closed as off-topic by David Richerby, Derek Elkins, Evil, fade2black, Yuval Filmus Oct 22 '17 at 7:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about computer science, within the scope defined in the help center." – David Richerby, Derek Elkins, Evil, fade2black
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ 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. $\endgroup$ – greybeard Oct 22 '17 at 2:28
  • $\begingroup$ @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. $\endgroup$ – Rahul Oct 22 '17 at 2:43
  • $\begingroup$ Programming questions are off-topic here but on-topic on stackoverflow. $\endgroup$ – Yuval Filmus Oct 22 '17 at 7:16
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ The code as written seems syntactically incorrect. $\endgroup$ – greybeard Oct 22 '17 at 8:22
  • $\begingroup$ 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 :) $\endgroup$ – Rahul Oct 22 '17 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.