1 registered members (henrybane),
1,246
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: Nadester]
#19004
12/20/05 00:22
12/20/05 00:22
|
Joined: Oct 2003
Posts: 1,550 United Kingdom
indiGLOW
Serious User
|
Serious User
Joined: Oct 2003
Posts: 1,550
United Kingdom
|
Yeah I would smack my self in the face for reviving an old topic, but I actually was in need of this, had forgotten how to implement it, and there it was on my favourites list. I don't think this ever was taken as far as it could be, using the square numbers meant the definition text was growing at an incredible length lol I am gonna have to get up early and chew the fat on your take on bitwise implementation! Thanks for not chewing my face off for dragging the post up again ![](/ubbthreads/images/graemlins/smile.gif)
The Art of Conversation is dead : Discuss
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: indiGLOW]
#19005
12/21/05 12:46
12/21/05 12:46
|
Joined: Oct 2003
Posts: 1,550 United Kingdom
indiGLOW
Serious User
|
Serious User
Joined: Oct 2003
Posts: 1,550
United Kingdom
|
I just been talking to someone about using this method for node based path finding? Im thinking that, each node has the skills set to the appropriate square number, incremented for ALL nodes, then a route through the nodes, could be stored like this...but could it also help work it out? I mean if you know the target node is 64, can you work out the route? Just thinking out loud ![](/ubbthreads/images/graemlins/laugh.gif)
The Art of Conversation is dead : Discuss
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: VeT]
#280393
07/22/09 13:54
07/22/09 13:54
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
wow, how long have you been searching to find this old thread? 2005 ![smile smile](/ubb7/images/graemlins/default_dark/smile.gif) I agree though, very important stuff here. Just see the potential for mutliplayer games! If I have four guns and want to tell another user which of these was fired, with this I only need to send one value instead of 4... Just a question though: has this changed now that we use LiteC and not Cscript? How would you code the same thing with liteC?
Last edited by Germanunkol; 07/22/09 13:54.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: Germanunkol]
#280408
07/22/09 14:40
07/22/09 14:40
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
#define setBit( x, n ) ( x |= (1<<n) ) //puts bit n in x on true (n=3, 10110 | 01000 = 11110 ) #define resetBit( x, n ) ( x ^= (1<<n) ) //puts bit n in x on false (n=3, 10110 ^ 00100 = 10010)
#define getBit( x, n ) ( x & (1<<n) ) //returns true when bit n in x is set (n=3, 10110 & 00100 = 00100 so TRUE ) (n=4, 10110 & 01000 = 00000 so FALSE)
int weaponsFired = 0; setBit( weaponsFired, 3 ); //player 3 has fired (0000 | 0100 = 0100) setBit( weaponsFired, 1 ); //player 1 has fired (0100 | 0001 = 0101)
if( getBit( weaponsFired, 3 ) ) { die(); } //we die due to player 3 (0101 & 0100 = TRUE)
resetBit( weaponsFired, 3 ); //player 3 stopped shooting, player 1 not (0101 ^ 0100 = 0001)
Last edited by Joozey; 07/22/09 22:13.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: Germanunkol]
#280495
07/22/09 22:09
07/22/09 22:09
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
I did made a minor mistake by not stating that the FALSE example is n=4. ((1<<4) makes 1000, (1<<3) makes 0100) From what I understand from your post you read the bits from left to right. But bits are to be read from right to left, and the remaining 0's are actually redundant.
0001 = 1 = 1 0010 = 10 = 2 0011 = 11 = 3 0100 = 100 = 4 0101 = 101 = 5 ...
Last edited by Joozey; 07/22/09 22:16.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Tutorial: bitwise"&" operator use, **very usef
[Re: Joozey]
#280521
07/23/09 06:41
07/23/09 06:41
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
no I also read from right to left but I guess I had a mistake in my thoughts somewhere else. I assumed that the shifting starts with zero, so (1<<0) would make 0001 and (1<<3) makes 1000 But I guess thats wrong here. Sorry for disturbing ![wink wink](/ubb7/images/graemlins/default_dark/wink.gif)
|
|
|
|