PDA

View Full Version : Problem



hateshinai
11-02-2007, 04:20 PM
I have a weird problem. I'm making a LoadBMP function for the graph unit and as you may know, 1 and 4 bit bmp files can hold multiple pixels in a byte. I must read 1 pixel at a time so I used a loop and Shr and Shl to get what I need.

but I got a problem:

( FF (11111111) shl 0 ) shr 4 >> 0F (00001111) - this was fine for me, but

( FF (11111111) shl 4 ) shr 4 >> FF (11111111) - why is this so? I thought the result would be 0F again.

Does freepascal *save* the shifted bits?

I thought they get deleted, but it got them back. Can someone explain please !

dmantione
11-02-2007, 04:37 PM
Free Pascal is a 32 bit compiler, so $ff shl 4= $ff0. Then $ff0 shr 4=$ff.

However, byte($ff shl 4)=$f0 , so adding a typecast gives the result you need.

hateshinai
11-02-2007, 04:53 PM
Thanks! I didn't know of such typecasts.

No wonder you're called the Byte Master :D

savage
11-02-2007, 07:23 PM
hateshinai could you please post a more detailed subject in future. "Problem" is a bit too vague and may get overlooked due to lack of specific information.