In my experience this is 15-bit color (5 bits per color), the GBA for example uses this sort of color. The bits are generally stored like this:
0bbbbbgg gggrrrrr
Generic code:
color = 0x1234; //in binary this is 00010010 00110100
r = color & 0x1F; //1F in binary is 11111 - bitmask to isolate red
g = (color >> 5) & 0x1F; //similar except shift the bits to isolate blue
b = (color >> 10) & 0x1F;
Hope this helps.
I know the question has been answered, but... >_>
Write either "0BBBBBGGGGGRRRRR" or "byte 0 = GGGRRRRR; byte 1 = 0BBBBBGG".
And some more code:
const Bit0 = 1 << 0; // e.g. in a header file
const Bit1 = 1 << 1;
const Bit2 = 1 << 2;
const Bit3 = 1 << 3;
const Bit4 = 1 << 4;
const Bit5 = 1 << 5;
const Bit6 = 1 << 6;
const Bit7 = 1 << 7;
const Bit8 = 1 << 8;
const Bit9 = 1 << 9;
const Bit10 = 1 << 10;
const Bit11 = 1 << 11;
const Bit12 = 1 << 12;
const Bit13 = 1 << 13;
const Bit14 = 1 << 14;
const Bit15 = 1 << 15;
const Bits0 = Bit0 - 1;
const Bits1 = Bit1 - 1;
const Bits2 = Bit2 - 1;
const Bits3 = Bit3 - 1;
const Bits4 = Bit4 - 1;
const Bits5 = Bit5 - 1;
const Bits6 = Bit6 - 1;
const Bits7 = Bit7 - 1;
const Bits8 = Bit8 - 1;
const Bits9 = Bit9 - 1;
const Bits10 = Bit10 - 1;
const Bits11 = Bit11 - 1;
const Bits12 = Bit12 - 1;
const Bits13 = Bit13 - 1;
const Bits14 = Bit14 - 1;
const Bits15 = Bit15 - 1;
Color = 0x1234; // in binary this is 1001000110100
R = (Color ) & Bits5;
G = (Color >> 5 ) & Bits5;
B = (Color >> 10) & Bits5;
These bit constants make the code more readable IMO, and you don't have to write hex literals or even use the calculator.
if i get value from rom, should i reverse byte before covert. for example value in rom is 0x1234. should i reverse byte to 0x3412 first
Only if the emulated hardware is of another
endianess than the hardware your code's running on.