Hex Converter
#1

Hey,

I need to convert this hex code:
Код:
#RRGGBBAA
to:
Код:
0xAARRGGBBB
And please, do not give me these kind of functions:
Код:
stock HexToInt(string[]) // By DracoBlue
{
  	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;
}

stock HexToRGBA(colour, &r, &g, &b, &a) //By Betamaster
{
	r = (colour >> 24) & 0xFF;
	g = (colour >> 16) & 0xFF;
	b = (colour >> 8) & 0xFF;
	a = colour & 0xFF;
}

stock RGBA2ARGB(rgba)
{
    new src[4];
    for(new j = 0; j < 4; j++) src[j] = (!(24-(8*j)) ? rgba : (rgba >> (24-(8*j)))) & 0x000000FF;
    return (src[3] * 16777216) + (src[0] * 65536) + (src[1] * 256) + src[2];
}

stock RGBAToARGB( rgba )
    return rgba >>> 8 | rgba << 24;
I tried these all, never succeed converting it.

Thanks in advance, Ran
Reply
#2

Its ok
pawn Код:
stock RGBAToARGB( rgba )
    return rgba >>> 8 | rgba << 24;

    new argb = 0xFFFF00FF;
    new col = 0xFF00FFFF;
    printf("%d | %d",argb, RGBAToARGB( col ));
    // result -65281 | -65281
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Its ok
pawn Код:
stock RGBAToARGB( rgba )
    return rgba >>> 8 | rgba << 24;

    new argb = 0xFFFF00FF;
    new col = 0xFF00FFFF;
    printf("%d | %d",argb, RGBAToARGB( col ));
    // result -65281 | -65281
......
Reply
#4

Bump.
Reply
#5

For what? You've been given the answer.
Reply
#6

Why exactly would you need this?
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
For what? You've been given the answer.
Look at it again.
Quote:
Originally Posted by sammp
Посмотреть сообщение
Why exactly would you need this?
I convert #RRGGBBAA colour from a file and need to convert this into 0xAARRGGBB in order to use the SetMaterialObject.
Reply
#8

Quote:
Originally Posted by ranme15
Посмотреть сообщение
Look at it again.

I convert #RRGGBBAA colour from a file and need to convert this into 0xAARRGGBB in order to use the SetMaterialObject.
Tbh converting it manually would have been quicker than posting here :P :P :P
Reply
#9

Example code
pawn Код:
new hex,line,AARRGGBB;
while(fread(file,str))
{
    if(str[0] == '#')
    {
        strdel(str,0,1);
        strins(str,"0x",0);
    }
    if(sscanf(str,"x",hex))
    {
        printf("error in line %d", ++line);
        continue;
    }
    AARRGGBB = RGBAToARGB( hex ); // your aarrggbb
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)