Z
zacariaz
I have a random inteeger that i need to check if meet a certain
criteria. The criteria is that when converted to binary it consist only
of 1's, no 0's.
If that criteria is met i allso need to know how many 1's it consist
of.
Values that would meet the first criteria is fx.
3
7
15
and the output i need will be:
3 = 2
7 = 3
15 = 4
it all seems fairly simple, but i cant seem to figure out how to do it
in a proper way. I could probably do some magic with log2, but that is
not the way i want to do it.
Any suggestions?
Thanks in advance.
Regards
criteria. The criteria is that when converted to binary it consist only
of 1's, no 0's.
If that criteria is met i allso need to know how many 1's it consist
of.
Values that would meet the first criteria is fx.
3
7
15
and the output i need will be:
3 = 2
7 = 3
15 = 4
it all seems fairly simple, but i cant seem to figure out how to do it
in a proper way. I could probably do some magic with log2, but that is
not the way i want to do it.
Any suggestions?
Thanks in advance.
Regards