Bit Functions -
AbyssMorgan - 09.10.2015
Include contains functions for manipulating bits / cells.
PHP Code:
/****************************************************************************************************
* *
* )( Bit Functions )( *
* *
* Copyright © 2019 Abyss Morgan. All rights reserved. *
* *
* Website: adm.ct8.pl *
* Download: adm.ct8.pl/r/download *
* *
* Plugins: None *
* Modules: None *
* *
* File Version: 1.8.0 *
* *
* bit 0 - 31: *
* (bit 31) --> 11111111000000001111010001010000 <-- (bit 0) *
* *
* Example cell mode: *
* Mode 2 (cell id 15) --> 11 11 11 11 00 00 00 00 11 11 01 00 01 01 00 00 <-- (cell id 0) *
* Mode 4 (cell id 7) --> 1111 1111 0000 0000 1111 0100 0101 0000 <-- (cell id 0) *
* Mode 8 (cell id 3) --> 11111111 00000000 11110100 01010000 <-- (cell id 0) *
* Mode 16 (cell id 1) --> 1111111100000000 1111010001010000 <-- (cell id 0) *
* *
* General Macros: *
* GetValueBit(value,bit); *
* SetValueBit(&value,bit,power); //power 0 or 1 *
* SetValueBitTrue(&value,bit); *
* SetValueBitFalse(&value,bit); *
* GetCellValue(value,cellid,mode); *
* SetCellValue(&value,cellid,mode,power); *
* GetCellValueEx(value,offset,cellsize); *
* SetCellValueEx(&value,offset,cellsize,power); *
* InvertValue(value); *
* InvertValueEx(value,key); //default key 0xFFFFFFFF *
* bool:CheckValue(value,&count=0); //even - false,uneven - true *
* *
* File Byte Macros: *
* ExtractValue(value,&byte1,&byte2,&byte3,&byte4); *
* ExtractFloat(Float:value,&byte1,&byte2,&byte3,&byte4); *
* MergeValue(&value,byte1,byte2,byte3,byte4); *
* MergeFloat(&Float:value,byte1,byte2,byte3,byte4); *
* MergeValueEx(byte1,byte2,byte3,byte4); *
* Float:MergeFloatEx(byte1,byte2,byte3,byte4); *
* *
* Dynamic Toggle Config Macros: *
* GetConfigAddress(itemid); *
* GetConfigBit(itemid); *
* GetConfigSize(max_items); *
* IsToggleConfigInformation(variable,itemid); *
* ToggleConfigInformation(variable,itemid,value); //values: 1/0 *
* *
****************************************************************************************************/
Download:
BitFunctions.inc
Example:
PHP Code:
new ExampleConfig[GetConfigSize(MAX_PLAYERS)];
//get:
IsToggleConfigInformation(ExampleConfig,playerid);
//set:
ToggleConfigInformation(ExampleConfig,playerid,1);
Value Extract/Merge:
PHP Code:
new val = 0x89ABCDEF;
new a, b, c, d;
ExtractValue(val,a,b,c,d);
printf("%x %x %x %x",a,b,c,d); //prints 89 AB CD EF
new tmp = 0;
MergeValue(tmp,a,b,c,d);
printf("%x",tmp); //prints 89ABCDEF
Re: Bit Functions -
n0minal - 09.10.2015
Snippets, you could make better stuff such as bitwise bitshift and so on, convert RGB to RGBA or ARGB (would be more appreciated), btw the XOR operator "^" works fine in pawn, what's wrong on use it instead of a macro? lol
Re: Bit Functions -
AbyssMorgan - 09.10.2015
[deleted]
Re: Bit Functions -
AbyssMorgan - 06.02.2016
updated
GetValueBit, InvertValue, InvertValueEx - use macros
SetValueBit - less operations to perform
added new macros
PHP Code:
ExtractValue(value, &byte1, &byte2, &byte3, &byte4);
ExtractFloat(Float:value, &byte1, &byte2, &byte3, &byte4);
MergeValue(&value, byte1, byte2, byte3, byte4);
MergeFloat(&Float:value, byte1, byte2, byte3, byte4);
Re: Bit Functions -
AbyssMorgan - 15.03.2016
updated (faster)
PHP Code:
SetValueBit(&value, bit, power); //power 0 or 1
Added new macros:
PHP Code:
SetValueBitTrue(&value, bit);
SetValueBitFalse(&value, bit);
SetCellValue(&value, cellid, mode, power);
GetCellValue(value, cellid, mode);
MergeValueEx(byte1, byte2, byte3, byte4);
Float:MergeFloatEx(byte1, byte2, byte3, byte4);
Function SetCellValue and GetCellValue
They are used to manipulate the n bit cells
Example:
PHP Code:
printf("%d, %d",GetCellValue(0x89ABCDEF,1,3),GetCellValue(0x89ABCDEF,1,8));
//print: 5, 205
//mode 3: 10 001 001 101 010 111 100 110 111 101 111 <-- cell id 0
//cell id 1 = 0b101 = 5
//mode 8: 10001001 10101011 11001101 11101111 <-- cell id 0
//cell id 1 = 0b11001101 = 205
Re: Bit Functions -
iKevin - 15.03.2016
Good stuff. But I guess it's not so useful
Re: Bit Functions -
AbyssMorgan - 27.03.2017
Update v1.8.0:
- Added macros:
PHP Code:
GetConfigAddress(itemid);
GetConfigBit(itemid);
GetConfigSize(max_items);
IsToggleConfigInformation(variable,itemid);
ToggleConfigInformation(variable,itemid,value);
- Example code:
PHP Code:
//vehicle
new ark[GetConfigSize(MAX_VEHICLES)];
for(new i = 0; i < MAX_VEHICLES; i++){
ToggleConfigInformation(ark,i,1);
}
//player
new ExampleConfig[GetConfigSize(MAX_PLAYERS)];
//get:
IsToggleConfigInformation(ExampleConfig,playerid);
//set:
ToggleConfigInformation(ExampleConfig,playerid,1);
Re: Bit Functions -
czop1223 - 28.05.2017
Could I get an example of something like
player can have 4 types of documents, i could have it done by having arrays like hasDocumentA hasDocumentB, but how do I do it using bits?
Re: Bit Functions -
AbyssMorgan - 28.05.2017
e.g. one variable
PHP Code:
new PlayerDocument[4][GetConfigSize(MAX_PLAYERS)]; //4 * 32 * 4 B = 512 Bytes
//new bool:PlayerDocument[4][MAX_PLAYERS]; //4 * 1000 * 4 B = 16000 Bytes
PHP Code:
//get: documentid 0 - 3
if(IsToggleConfigInformation(PlayerDocument[documentid],playerid)){
}
//set:
ToggleConfigInformation(PlayerDocument[documentid],playerid,1); //1 or 0
Re: Bit Functions -
czop1223 - 02.06.2017
thanks man, appreciated !