Skip to main content
gamedev.net
🔒 Locked

Tough Algorithm?

Started by Gf11speed 9 replies 1k views
Original Post
Gf11speed
Gf11speed
For some reason, I can't think of a way to do this. Say I have some numbers: (not necessarily in order) 0 1 2 3 4 and I want to find all the bit sequences that add up to a certain #. For example, if that # is 6. I would get the bit combitions: 11110 01110 10101 00101 .. this means that, for the bit combinations 11110, the numbers: 0 1 2 3 .. all add up to 6. For the bit combo 10101: 0 2 4 ... all add up to 6. Etc. How could I do this? I don't know if I explained this clearly, but thanks for any help you can give. [edited by - Gf11speed on October 13, 2003 12:01:17 AM]
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
doogle
doogle
quote:
Original post by Anonymous Poster
go learn what the bitwise operators (&, |, and ~) do. this is not a difficult problem.


Do you mean ^ instead of ~? I have never heard of a ~ operator before.
Rayno
Rayno
~ is the bitwise NOT operator. It gives you the opposite of a binary number. For example, the bitwise NOT of 100101 would be 011010.

[edited by - rayno on October 13, 2003 12:36:44 AM]
Gf11speed
Gf11speed
I''m not all that advanced now
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Rayno
Rayno
It isn''t as complicated as it sounds.

Observe:

...
unsigned short SomeVar = 5; //0000000000000101 in binary

SomeVar = ~SomeVar; //SomeVar now equals 1111111111111010 in binary because ~ just flips all the bits.

//That is 65530 in decimal numbers, by the way.
Nekhmet
Nekhmet
Does it have to be fast? And how big is the list of numbers?

- Josh
Bunnz
Bunnz
do you want to get the bits of the binary system or of the "special" system you have used within you examples???

Because if you really want to use your "special" system, the binary operators won''t help!
Have fun BunnzPunch'n'Crunch

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.