I prefer this system instead of decimal system. Why?
It's easier to convert those integers to binary system which is used by computers. It also looks kinda cooler
Some examples of integers in HEX system
0xFF
0x10
0x25
0xA
0xAF
How to convert HEX integer into decimal one?
It is quite easy.
0x10
Just don't mind about this first zero. Imagine that x = 16.
0x10 = x(16) * 1 + 0 = 16
Just multiple first number after x (As I said imagine that x = 16)
The rest integers you have to sum.
We multiplied 16 by 1 and we add there a 0
Some more examples
0x21 = x(16) * 2 + 1 = 33
0xFF = x(16) * 15 + 15 = 255
Oh wait! What is this 'F' character?
In this system you can also use letters instead of numbers.
Code: Select all
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15Compiler detects that this integer is in HEX System by 0x at the begining.
You don't need to use this zero in conversion.
How would it look in a PAWN script?
Code: Select all
#include <amxmodx>
#define VERSION "0.1"
new const g_iHEX[] = {
0x14, //20
0x25, //37
0x15, //21
0x05, //5
0x50, //80
0xA, //10
0xFF //255
};
public plugin_init() {
register_plugin("HEX TO DEC", VERSION, "diablix")
register_clcmd("say /test", "cmdHexToDec");
}
public cmdHexToDec(id){
new sMessage[0x80]; // 0x80 = 16 * 8 + 0 = 128
new iMesSize = formatex(sMessage, sizeof sMessage - 1, "DEC READEN FROM HEX : ");
for(new i = 0 ; i < sizeof g_iHEX ; i ++)
iMesSize += formatex(sMessage[iMesSize], (sizeof sMessage - 1) - iMesSize, "%d ", g_iHEX[i]);
set_pev(id, pev_effects, g_iHEX[5]); // 0xA = 16 * A(10) = 16
client_print(id, 3, sMessage);
return 1;
} 