1. Palette storage... Shifting...

13h game. DJGPP. Windows95

Will someone please explain to me what Brackeen
is doing when he's shifing the return value
of fgetc(fp)?

Code:
```for(index=0;index<num_colors;index++)
{
b->palette[(int)(index*3+2)] = fgetc(fp) >> 2;
b->palette[(int)(index*3+1)] = fgetc(fp) >> 2;
b->palette[(int)(index*3+0)] = fgetc(fp) >> 2;
x=fgetc(fp);
}```
Is there a specific reason why he's doing this
(as in, does it have to be done in order for
the palette to be stored correctly?), or is
it just for speed? I understand what shifting does,
but I'm not quite comfortable with it, yet.

Thanks,
static.

2. ultimately it depends upon the context of the program... but it looks to me like he's reading a palette from a 256 color bitmap... and translating 8 bit rgb values to 6 bit... which is what you'd pass to the pallete ports... [you have 2^18 colors... but only 256 indexes for them...]

anything else?

hth!

3. That's exactly what he is doing. If you do not do this, your palette will look ugly since you will lose significant bits in your color info if you try to set palette entries in mode 13h.

He is dividing by 4.

4. I thought shifting gave the effect of multiplication
(that's what Brackeen says).

If the Red-value that was read was shifted twice,
wouldn't it be the same as multiplying by four,
instead of dividing. Yeah, I know you're right
(my program even shows that the RGB values were
divided by 4), but why does this work?

If the value that fgetc() returned was shifted
to the left twice, wouldn't that be like saying:

2^2fgetc();
4 * fgetc();

Thanks,
static.

5. since binary is base two, shifting it per position would be increasing it by a factor of 2, or decreasing it by a factor of 2... so, if you shift multiple times, you get the compound effect...

6. Am I an idiot...?

fgetc(file) >> 2; is shifing to the right, which
means the number is being divided by 4...

fgetc(file) << 2; is shifing to the left, which
means the number is being multiplied by 4...

Am I correct? Eh, I didn't even know about
shifting-right... Argh! Sometimes I just feel
so stupid!!!

7. >Am I an idiot...?

sure you want me to answer that? hehe... worry not! logik to the resque!