SEARCH HOME
 Math Central Quandaries & Queries
 Question from Abraham: I have seen programs with options and I wish to create a similar program. I have options 1 2 4 8 16 32 64 128 etc. If I receive option 3 means option 1 and 2 are included. Option 20 means option 16 and 4 are included. that because of the sum of those numbers is the only way to get the given number. I want to know if is there a way to know which number from options are included. How I know: 1 is Included 2 is Included 4 is Included Thanks for helping me

Yes you can.

The easiest thing is to divide by the number, ignoring the "remainder". Then see if the dividend is odd. If it is odd, the number is included.

For example, is "8" included by 28703?

28703 / 8 = 3587 remainder 7. Since 3587 is odd, then 8 is indeed included by 28703.

Cheers,
Stephen La Rocque