Calculating hex - 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)
+--- Thread: Calculating hex (
/showthread.php?tid=420345)
[solved] Calculating hex -
Misiur - 04.03.2013
How to calculate 0xXXXXXXFF from 0xXXXXXX? I don't know how to operate on older bytes, so I assume there has to be some shifting.
#e: Argh, is it even possible to store this thing in single cell?
#e2
Solution:
Ok, so numbers over 0xFFFFFF are stored as negative:
pawn Код:
new a = 0xABCDEF;
new b = 0x000000FF;
new c = (a << 8) | b; //0xABCDEFFF
Re: Calculating hex -
Azazelo - 04.03.2013
// Author: DracoBlue
http://forum.sa-mp.com/index.php?top...sg8635#msg8635
pawn Код:
HexToInt(string[]){
if (string[0]==0) return 0;
new i;
new cur=1;
new res=0;
for (i=strlen(string);i>0;i--) {
if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
cur=cur*16;
}
return res;
}
Edition WhiteJoker
pawn Код:
stock HexToInt(string[])
{
if (string[0] == 0)
{
return 0;
}
new i;
new cur = 1;
new res = 0;
for (i = strlen(string); i > 0; i--)
{
if (string[i-1] < 58)
{
res = res + cur * (string[i - 1] - 48);
}
else
{
res = res + cur * (string[i-1] - 65 + 10);
cur = cur * 16;
}
}
return res;
}
May this be helpful to you