PDA

Просмотр полной версии : [Include] DataConvert



AbyssMorgan
17.08.2021, 11:36
Здравствуйте, я хотел бы представить простую библиотеку для преобразования чисел между системами, десятичными, шестнадцатеричными, двоичными, восьмеричными.



DataConvert.inc
Copyright © 2021 Abyss Morgan. All rights reserved.
Contributors: Crayder, Shiny

Website: https://adm.ct8.pl

Plugins: SScanf
Modules: None

File Version: 2.2.0
SScanf Version: 2.8.2

Definitions:
FIRST_FILE_ADDRESS
INVALID_FILE_ID
INVALID_FILE_HANDLE
INT_NUMBER_LEN
HEX_NUMBER_LEN
BIN_NUMBER_LEN
OCT_NUMBER_LEN

Functions:
strcopy(const input[],output[]); //string copy for warning 224: indeterminate array size
fstrcopy(const input[],output[],maxdest = sizeof(output)); //fast string copy
ABCToCBA(const input[],output[]);
AnyToInt(string[],type,&bool:flag);
IntToAny(value,output[],type);
rot13(string[]);
code128(const input[],output[]);
swap_int({Float,_}:int1,{Float,_}:int2);
swap_string(string1[], string2[], dest1 = sizeof(string1), dest2 = sizeof(string2));
ContainInSeries(value,...);
ContainInSeriesFloat(Float:value,Float:...);
StringEqual(string1[],string2[],ignorecase);
StringNotEqual(string1[],string2[],ignorecase);
base64_decode(const input[],output[]); //d:base64
base64_encode(const input[],output[]); //e:base64
StripNewLine(string[]);
strreplace(string[],const search[],const replacement[],bool:ignorecase = false,pos = 0,limit = -1,maxlength = sizeof(string));
strlower(string[]);
strupper(string[]);
DataConvert::InvertString(const input[], output[], maxdest = sizeof(output));
DataConvert::StringToHexString(const input[], output[], maxdest = sizeof(output));
DataConvert::HexStringToString(const input[], output[], maxdest = sizeof(output));

File functions:
GetFileHandleID(File:handle);
GetFileID(File:handle);
fcopy(const input[],output[]);
frename(oldname[],newname[]);
DataConvert::FileCreate(const name[]);
DataConvert::MergeFile(const first_file[],const second_file[],bool:erase_second=false);
DataConvert::MergeFileGroup(const group_name[],const output[],upperbound_index,bool:erase_input=false);
DataConvert::SplitFile(const input[],const output[],max_size,&upperbound_index=0);

Validators:
IsDecimalNumber(const string[]);
IsHexNumber(const string[]);
IsBinaryNumber(const string[]);
IsOctalNumber(const string[]);
IsFloatNumber(const string[]);

Convert to Bool:
StringToBool(const string[]);
IntToBool(value);

Convert to Int:
StringToInt(const string[]);
BoolToInt(bool:boolean);
HexToInt(const string[]);
BinToInt(const string[]);
OctToInt(const string[]);

Convert to Hex:
IntToHex(value);
IntToHexEx(value);
BinToHex(const string[]);
BinToHexEx(const string[]);
OctToHex(const string[]);

Convert to Bin:
IntToBin(value);
HexToBin(const string[]);
OctToBin(const string[]);

Convert to Oct:
IntToOct(value);
HexToOct(const string[]);
BinToOct(const string[]);

Binary Data Convert:
FloatToInt(Float:value); //Convert Float binary data to Integer binary data !
IntToFloat(value); //Convert Integer binary data to Float binary data !


Примеры:


new File:edi = fopen("test.txt",io_readwrite);
new id = GetFileID(edi); //возвращает номер открытого файла: 1, 2, 3, 4, ...

new a = BinToInt("1010"); //возвращение 10

new hex[10];
hex = IntToHex(15); //возвращение 00000F
hex = IntToHexEx(15); //возвращение F

new g = 15, Float:h = 15.0;
if(IsIdentical(g,h)){ //Этот оператор можно использовать только с переменными
printf("YES");
} else {
printf("NO"); //<-- распечатать это
}

new buf[128];
ABCToCBA("Hello",buf);
printf(buf); //print: olleH

new v1 = 15, v2 = 19;
swap_int(v1,v2); //swapvars by Crayder
//after operation: v1 = 19, v2 = 15

new test = FloatToInt(25666.000000); //возвращение 1187546112

new Float:test2 = IntToFloat(1084227584); //возвращение 5.0

//http://www.rot13.com
new rot[64];
rot = rot13("San Andreas Multiplayer"); //возвращение "Fna Naqernf Zhygvcynlre"

//ContainInSeries(Float)

new myvalue = 431;

//if(myvalue == 425 || myvalue == 430 || myvalue == 432 || myvalue == 447 || myvalue == 464 || myvalue == 476 || myvalue == 520)
if(ContainInSeries(myvalue,425,430,432,447,464,476,520)){ //военная техника
printf("#1 YES");
} else {
printf("#1 NO"); //<-- распечатать это
}

//if(myvalue != 425 && myvalue != 430 && myvalue != 432 && myvalue != 447 && myvalue != 464 && myvalue != 476 && myvalue != 520)
if(!ContainInSeries(myvalue,425,430,432,447,464,476,520)){
printf("#2 YES"); //<-- распечатать это
} else {
printf("#2 NO");
}

new Float:myfloatvalue = 15.0;
if(ContainInSeriesFloat(myfloatvalue,12.0,1.0)){
printf("#3 YES");
} else {
printf("#3 NO"); //<-- распечатать это
}


Скачать:
DataConvert.inc (https://adm.ct8.pl/cloud/Libs/DataConvert/DataConvert.inc)
GitHub (https://github.com/AbyssMorgan/SAMP/blob/main/Libs/DataConvert/DataConvert.inc)

Эта тема переведена, автор не может полностью помочь на русском языке.