Question... (bits and binary)
#1

Hi, I know what binary is and what the bitwise operators do. But, what are the advantages of using bit manipulations? I also see 'if(x << y)' things. Can you show me examples?
Reply
#2

Normal variable in pawn (called cell) has 32 bits. Without using bit flags you can't access any part smaller than 8 bits at once (and to get 8, you have to use packed strings). With bit operations you can access any bit you want. https://sampforum.blast.hk/showthread.php?tid=216730 - take a look at "bit-flags in enums", that's real world example.

Also it's handy for colors manipulation - https://sampforum.blast.hk/showthread.php?tid=200876

Also when your script reaches complexity of at least O(n^2), even smallest optimisations can really speed things up.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)