Link to home
Start Free TrialLog in
Avatar of jl66
jl66Flag for United States of America

asked on

algorithm: how to seperate a number into a group of small numbers

1) there are 6 numbers 1,2,4,8,16,32,64. Increase by power 2.
2) given a number N <=64, for example 59, see what numbers in 1) consist of 59.
3) a number can be used only once.
It's better to code in DOS shell.
For example, 59 = 32+16+8+2+1
ASKER CERTIFIED SOLUTION
Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jl66

ASKER

Excellent. One more question: if the number < 1,200,000,000, it's OK. Do you have any idea when the number is larger than it, say 8,000,000,000?
Avatar of Qlemo
This will work only for 32bit signed integer, meaning 2,17 billion.

The algorithm is standard binary coding, because of "power 2" in point 1. Why to obscure that fact? Sounds like homework ...

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jl66

ASKER

Not homework but simplied real issue.