binary representation
Could you please help me answer this question, it means a lot to me.
Write a function CountOnes which takes an unsigned integer and returns the number of 1''s in its binary representation.
I need this very badly, please at least give a hint, or show me some source code. C/C++
Thank you very much for your time.
||||-- Our creation is the transformation of one. --|||
Let''s see what you have so far. Post your ideas from what you have researched to solve the problem, and maybe some code you''ve tried to write. I''m sorry but I ain''t doing any homeworks.
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
A hint, yes.
Okay, here''s what you''d do:
#ifdef WINDOWS
#define NUMBER_OF_BITS 32
#else
#define NUMBER_OF_BITS 16
#endif
counter = 0
for i = 0 to NUMBER_OF_BITS-1
if input_number AND 2^i then
counter = counter + 1
goto for
Now counter contains the number of 1''s that you have in input_number.
Hope this helps you some!
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
Okay, here''s what you''d do:
#ifdef WINDOWS
#define NUMBER_OF_BITS 32
#else
#define NUMBER_OF_BITS 16
#endif
counter = 0
for i = 0 to NUMBER_OF_BITS-1
if input_number AND 2^i then
counter = counter + 1
goto for
Now counter contains the number of 1''s that you have in input_number.
Hope this helps you some!
-------------------------------
That's just my 200 bucks' worth!
..-=gLaDiAtOr=-..
I''m not asking you to answer the whole question, i just need a hint, or an idea, or some kind of help.
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
Yes, thank you Gladiator.
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
More ideas? commentaries, suggestions?
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
||||-- Our creation is the transformation of one. --|||
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement