Calculating hex
#1

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
Reply
#2

// 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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)