   gif format - some problems
  i've some problems writing a gif class to open a gif image. as said here i need to read out 1 byte for the 'Background Color Index' field.but i need to access the bits. this confuses me a bit (haha, joke ^^)...globalcolortable = h2.bgcolindex>>7;'globalcolortable' is a bool and the bgcolorindex is a char, wich holds the 'Background Color Index' data. but i am not shure if this is correct. what kind of value will be returned to the bool? when i do thisint b = h2.bgcolindex>>7;b gets set '-1', i assume this is because the first bit of an integer says if it is larger zero or lower zero...do i need to return the absolute value of bgcolorindex to the bool? or something else?another thing is the access of the other bits:will (h2.bgcolorindex<<4)>>7 work to access the 5th bit? this really confuses me, since i never really worked with these bit operators. i hope you can help me :)[Edited by - SiS-Shadowman on May 27, 2006 4:43:51 PM]
  I do not know much about the gif file format but I can help you accessing the bits:#include <stdio.h>int GetBit(__int8 x,int bit){return(((x & (1<<bit)) == 0) ? 0  : 1);}void main(){__int8 x=0x2E;// 0010 1110for(int i=7;i>=0;i--) printf("%d",GetBit(x,i));printf("\n");}// accessing the 3th bit:// x    = 0010 1110// 1<<3 = 0000 1000// & ---------//   0000 1000 > 0 => "3th bit = 1";  thank you very much, i'll implement it :)can you tell me how i can access multible bytes? i'm not shure how do to this.char blub; // 8 bitsshort color_res; // it needs bits 1 to and with 4 of 'blub'color_res = (blub<<1)>>5; // first it deletes bit 0, then it deletes everything from bit 4 to 7. everything on the left side from bit 1 will then be 0.is this the right way to access these bits? i'm really not shure   ;Quote:Original post by SiS-Shadowmanchar blub; // 8 bitsshort color_res; // it needs bits 1 to and with 4 of 'blub'color_res = (blub<<1)>>5; // first it deletes bit 0, then it deletes everything from bit 4 to 7. everything on the left side from bit 1 will then be 0.is this the right way to access these bits? i'm really not shureTo be honest it's a little tricky to figure out what you want from your explanation, but I think I got it.You want bits 1-4 of a byte? And you want the integer value those bits form? It's this simple:color_res = (blub & 0x0E) >> 1;;  when i'm right, 0x0E is a mask, that has every bit, except 1 to 4 set to 0, that will delete every bit out of blub, doesn't it?i think i'll understand how i need to do this.i just ask myself why the gif format saves information in signle bits than just one infoper byte, it wouldn't make the file much bigger -.-   