[HELP] Binary Bits - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Binary Bits (
/showthread.php?tid=208479)
[HELP] Binary Bits -
psoftware - 08.01.2011
Hey, i want to trasform this binary number 1010 in 4 numbers 1, 0, 1, 0. Can i do this
Re: [HELP] Binary Bits -
veyron - 08.01.2011
define
pawn Код:
#define GetBit(%0,%1) ((%0>>%1)&1) // GetBit(var,slot 0-31)
example (binary starts from right so numbers should be counted from right too, like 00000001 , 1 is bit 0)
make sure bit slot is not negative or above 31
pawn Код:
new bin = 0b01001010;
new nums[8];
for(new i=0;i<sizeof(nums);i++)
nums[i] = GetBit(bin,i);
im new to bitwise operations, so it may not be the best and most efficient way, but it should work
Re: [HELP] Binary Bits -
psoftware - 08.01.2011
Thanks a lot..... it works!!!!