Please anyone tell me how to convert array to hexadecimal variable
Code:Input: a = {255, 0, 0, 0 } I need output as a = FF000000 If input is a = {255, 255, 255, 255 } Output should be a = FFFFFFFF
Please anyone tell me how to convert array to hexadecimal variable
Code:Input: a = {255, 0, 0, 0 } I need output as a = FF000000 If input is a = {255, 255, 255, 255 } Output should be a = FFFFFFFF
Use printf() with the %02X formatter in a loop.
Mainframe assembler programmer by trade. C coder when I can.
Use sprintf() instead of printf().
Mainframe assembler programmer by trade. C coder when I can.
I'm sure you don't mean that array a holds the problem as well as the solution.
So something like this:Code:answer = a[0] << 24 | a[1] << 16 | a[2] << 8 | a[3];
OK there are a few confusions here. In your latest example you are passing three integers (I assume). The function should return a composite RGB value?
When you mentioned "Output should be a = FFFFFFFF" you meant you wanted an integer?
MaybeWhere 'a' is transparency or whatever? You didn't pass this value.Code:return a << 24 | R << 16 | G << 8 | B;
If you want to print out this 32-bit integer as a hex string useCode:printf("%08X", variable);
Last edited by nonoob; 08-13-2009 at 09:39 AM.