Hi,
given a char(8bit's), I want to get the value of every 2bits,
so that a char will contain 4 values.
This is easily done with a shift left command (<<2).
As far as I understand,
char arrays are simply the different chars in consecutive order in the memory.
so essentially, I should be able to just shift2, through the entire array.
This is a short snippet that does want I want but not in the correct way.
int main(int argc, char *arg[]){
unsigned char *chr = new unsigned char[8];
for(int i=0;i<8;i++)
chr[i] = 0x80 ;
int i=0;
unsigned char tmp;
while(i<8){
printf("11xx-xxxx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 1100 0000
tmp = tmp<<2;
printf("xx11-xxxx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
tmp = tmp<<2;
printf("xxxx-11xx bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
tmp = tmp<<2;
printf("xx11-xx11 bits of chr[%d]=%x\n",i,tmp&0xc0); //extract 0011 0000
i++;
}
Basicly i would like to avoid doing 4 times 2 shift for each char.
and just do shift2 all the way through the array.
like
while(chararray not empty){
print first 2 bits
shift chararray 2 bits
}
thanks in advance