Thanks for your help. This is my code. I have an unsigned char array with 36 elements.
Code:
unsigned char s[36]
#define bit_at(a,i) !!(a[i / 8] >> (8 - (i % 8) - 1) & 1) //I copy this code from our forum.
#define bit_clear(a,i) ((a) & ~(1 << (i)))
#define bit_set(a,i) ((a) | (1 << (i)))
void shiftbit(unsigned char *s, unsigned char t1, unsigned char t2, unsigned char t3){
int i;
unsigned char a=0;
unsigned char b=bit_at(s,7); //b is the 8th of previous byte
for (i=0;i<36;i++){
//a is the 8th bit
a=bit_at(s,(i+1)*8-1);
//shift right each byte
s[i]=s[i]>>1;
if (i!=0)
//if b=0, set the first bit of the byte to 0.
if (b==0) bit_clear(s[i],7);
else bit_set(s[i],7);
b=a;
}
My array s is:
11111010 10100111 01010100 00000001 10101110 01011011 00001000 10110101 01100010 00001111 00000000 00000110 00111011 00000111 11001100 10010001 01011110 00100010 11101111 10110100 01111001 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000111
After I shift, it is:
00000000 01010011 00101010 00000000 01010111 00101101 00000100 01011010 00110001 00000111 00000000 00000011 00011101 00000011 01100110 01001000 00101111 00010001 01110111 01011010 00111100 00100000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000011
That's my problem. Please help me. Thank you so much.