SA-MP Forums Archive
Question... (bits and binary) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question... (bits and binary) (/showthread.php?tid=491337)



Question... (bits and binary) - ACI - 30.01.2014

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?


Re: Question... (bits and binary) - Misiur - 30.01.2014

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.