SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 18/06/2016, 10:06 PM   #1
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Cool Data Convert (decimal / hexadecimal / binary)

Hello, I would like to present a simple include to convert numbers between systems, decimal, hexadecimal, binary.

PHP Code:
/*************************************************************************************************************************************
 *                                                                                                                                   *
 *                                                      )(   Data Convert   )(                                                       *
 *                                                                                                                                   *
 * Copyright © 2019 Abyss Morgan. All rights reserved.                                                                               *
 * Contributors: Crayder, Shiny                                                                                                      *
 *                                                                                                                                   *
 * Website:  adm.ct8.pl                                                                                                              *
 * Download: adm.ct8.pl/r/download                                                                                                   *
 *                                                                                                                                   *
 * Plugins: SScanf                                                                                                                   *
 * Modules: None                                                                                                                     *
 *                                                                                                                                   *
 * File Version: 2.1.1                                                                                                               *
 * 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(input[],output[]);  //string copy for warning 224: indeterminate array size                                               *
 * fstrcopy(input[],output[],maxdest = sizeof(output));   //fast string copy                                                         *
 * ABCToCBA(input[],output[]);                                                                                                       *
 * AnyToInt(string[],type,&bool:flag);                                                                                               *
 * IntToAny(value,output[],type);                                                                                                    *
 * rot13(string[]);                                                                                                                  *
 * code128(input[],output[]);                                                                                                        *
 * swap_int({Float,_}:int1,{Float,_}:int2);                                                                                          *
 * swap_string(string1[], string2[], dest1 = sizeof(string1), dest2 = sizeof(string2));                                              *
 * bool:ContainInSeries(value,...);                                                                                                  *
 * bool:ContainInSeriesFloat(Float:value,Float:...);                                                                                 *
 * StringEqual(string1[],string2[],ignorecase);                                                                                      *
 * StringNotEqual(string1[],string2[],ignorecase);                                                                                   *
 * base64_decode(input[],output[]); //d:base64                                                                                       *
 * base64_encode(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[]);                                                                                                               *
 *                                                                                                                                   *
 * File functions:                                                                                                                   *
 * GetFileHandleID(File:handle);                                                                                                     *
 * GetFileID(File:handle);                                                                                                           *
 * fcopy(input[],output[]);                                                                                                          *
 * frename(oldname[],newname[]);                                                                                                     *
 *                                                                                                                                   *
 * Validators:                                                                                                                       *
 * bool:IsDecimalNumber(string[]);                                                                                                   *
 * bool:IsHexNumber(string[]);                                                                                                       *
 * bool:IsBinaryNumber(string[]);                                                                                                    *
 * bool:IsOctalNumber(string[]);                                                                                                     *
 * bool:IsFloatNumber(string[]);                                                                                                     *
 *                                                                                                                                   *
 * Convert to Bool:                                                                                                                  *
 * bool:StringToBool(string[]);                                                                                                      *
 * bool:IntToBool(value);                                                                                                            *
 *                                                                                                                                   *
 * Convert to Int:                                                                                                                   *
 * StringToInt(string[]);                                                                                                            *
 * BoolToInt(bool:boolean);                                                                                                          *
 * HexToInt(string[]);                                                                                                               *
 * BinToInt(string[]);                                                                                                               *
 * OctToInt(string[]);                                                                                                               *
 *                                                                                                                                   *
 * Convert to Hex:                                                                                                                   *
 * IntToHex(value);                                                                                                                  *
 * IntToHexEx(value);                                                                                                                *
 * BinToHex(string[]);                                                                                                               *
 * BinToHexEx(string[]);                                                                                                             *
 * OctToHex(string[]);                                                                                                               *
 *                                                                                                                                   *
 * Convert to Bin:                                                                                                                   *
 * IntToBin(value);                                                                                                                  *
 * HexToBin(string[]);                                                                                                               *
 * OctToBin(string[]);                                                                                                               *
 *                                                                                                                                   *
 * Convert to Oct:                                                                                                                   *
 * IntToOct(value);                                                                                                                  *
 * HexToOct(string[]);                                                                                                               *
 * BinToOct(string[]);                                                                                                               *
 *                                                                                                                                   *
 * Binary Data Convert:                                                                                                              *
 * FloatToInt(Float:value); //Convert Float binary data to Integer binary data !                                                     *
 * Float:IntToFloat(value); //Convert Integer binary data to Float binary data !                                                     *
 *                                                                                                                                   *
 *************************************************************************************************************************************/ 
Examples:
PHP Code:
new File:edi fopen("test.txt",io_readwrite);
new 
id GetFileID(edi); //returns the number of open file: 1, 2, 3, 4, ...

new BinToInt("1010"); //return 10

new hex[10];
hex IntToHex(15); //return 00000F
hex IntToHexEx(15); //return F

new 15Float:15.0;
if(
IsIdentical(g,h)){ //This operator can only be used on variables
    
printf("YES");
} else {
    
printf("NO"); //<-- print this
}

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

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

new test FloatToInt(25666.000000); //return 1187546112

new Float:test2 IntToFloat(1084227584); //return 5.0

//http://www.rot13.com
new rot[64];
rot rot13("San Andreas Multiplayer"); //return "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)){ //millitary vehicles
    
printf("#1 YES");
} else {
    
printf("#1 NO"); //<-- print this
}

//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"); //<-- print this
} else {
    
printf("#2 NO");
}

new 
Float:myfloatvalue 15.0;
if(
ContainInSeriesFloat(myfloatvalue,12.0,1.0)){
    
printf("#3 YES");
} else {
    
printf("#3 NO"); //<-- print this

Download:
DataConvert.inc

Website:
Data Converter


Non-Registered Users:
Bug Report

Last edited by AbyssMorgan; 26/09/2019 at 05:37 PM. Reason: Update v2.1.1
AbyssMorgan is offline   Reply With Quote
Old 18/06/2016, 10:39 PM   #2
K0P
Banned
 
Join Date: Nov 2015
Location: *.*.*.*
Posts: 599
Reputation: 87
Default Re: Data Convert (decimal / hexadecimal / binary)

Nice Include +Rep
K0P is offline   Reply With Quote
Old 23/06/2016, 07:55 AM   #3
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 808
Reputation: 103
Default Re: Data Convert (decimal / hexadecimal / binary)

Very useful, great work.
__________________
SecretBoss is offline   Reply With Quote
Old 14/07/2016, 06:21 PM   #4
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Data Convert (decimal / hexadecimal / binary)

Update v1.7.2:

Added operators:
PHP Code:
bool:ContainInSeries(value,...);
bool:ContainInSeriesFloat(Float:value,Float:...); 
Example:

PHP Code:
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)){ //millitary vehicles
    
printf("#1 YES");
} else {
    
printf("#1 NO"); //<-- print this
}

//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"); //<-- print this
} else {
    
printf("#2 NO");
}

new 
Float:myfloatvalue 15.0;
if(
ContainInSeriesFloat(myfloatvalue,12.0,1.0)){
    
printf("#3 YES");
} else {
    
printf("#3 NO"); //<-- print this

AbyssMorgan is offline   Reply With Quote
Old 24/11/2016, 08:35 PM   #5
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Data Convert (decimal / hexadecimal / binary)

Update v1.8.0:

- Added macros:
PHP Code:
StringEqual(string1[],string2[],ignorecase);
StringNotEqual(string1[],string2[],ignorecase); 
- Added functions by Shiny:
PHP Code:
base64_decode(input[],output[]); //function extra name d:base64(input[],output[]);
base64_encode(input[],output[]); //function extra name e:base64(input[],output[]); 
AbyssMorgan is offline   Reply With Quote
Old 25/11/2016, 12:18 AM   #6
Ivan_Ino
Big Clucker
 
Join Date: Oct 2012
Location: Croatia
Posts: 101
Reputation: 120
Default Re: Data Convert (decimal / hexadecimal / binary)

Pretty cool work dude
Ivan_Ino is offline   Reply With Quote
Old 10/12/2016, 05:57 PM   #7
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Data Convert (decimal / hexadecimal / binary)

Update v1.9.0:

- Added functions:
PHP Code:
bool:IsDecimalNumber(string[]);
bool:IsHexNumber(string[]);
bool:IsBinaryNumber(string[]);
bool:IsFloatNumber(string[]); 
AbyssMorgan is offline   Reply With Quote
Old 11/12/2016, 02:13 AM   #8
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,948
Reputation: 504
Default Re: Data Convert (decimal / hexadecimal / binary)

Can you add support to octal ?
SyS is offline   Reply With Quote
Old 11/12/2016, 07:58 AM   #9
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Data Convert (decimal / hexadecimal / binary)

Quote:
Originally Posted by Sreyas View Post
Can you add support to octal ?
Yes, but I do not offer in this case such a fast conversion as in other systems.
AbyssMorgan is offline   Reply With Quote
Old 11/12/2016, 09:04 AM   #10
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,213
Reputation: 352
Default Re: Data Convert (decimal / hexadecimal / binary)

Update v2.0.0:

- Update for variable anti-collision
- Support for Octal
- Added functions:
PHP Code:
bool:IsOctalNumber(string[]);

OctToInt(string[]);
OctToHex(string[]);
OctToBin(string[]);

IntToOct(int);
HexToOct(string[]);
BinToOct(string[]); 
- Added definitions:
PHP Code:
INT_NUMBER_LEN
HEX_NUMBER_LEN
BIN_NUMBER_LEN
OCT_NUMBER_LEN 
- Fixed functions:
PHP Code:
BinToHex(string[]);
BinToHexEx(string[]);
IntToAny(value,output[],type); 
AbyssMorgan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert data itachi Scripting Help 0 14/04/2016 10:42 PM
[Pedido] Color Hexadecimal to Decimal VeNuZ_ PortuguÍs/Portuguese 9 17/08/2014 08:56 PM
convert to binary RicaNiel Scripting Help 0 04/10/2012 03:38 PM
Binary vs Decimal kurta999 Help Archive 0 16/02/2011 08:07 PM


All times are GMT. The time now is 02:36 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.