You're right, sorry for the mess.
Here's the code after modifications, yes e is from previous code I was working on and forgot it
But also, after removing e, the same problem still not solved.
Code:
uint8_t i,k,e;uint8_t buffer1[40],bit_mask[40]; // buffer1 for shifting data & bit_mask for saving the carried bit
for (k=0;k<40;k++){ // initialize both arrays to 0
buffer1[k]=0;bit_mask[k]=0;}
for (k=0;k<8;k++)
buffer1[k]=0x80; // put this value for testing in the first 8-bytes then shift it to the next 8-bytes
for (i=0;i<40;i++)
{
printf("shift %d\n",i); // prints no. of shifts
for (k=0;k<40;k++)
{
printf("0x%.2x\t",buffer1[k]); // print the data in order of 8-bytes at total of 40-bytes
if (k%8==7)printf("\n"); // after printing 8-bytes put a new line
}
printf("\n"); // new line after 40-bytes of each shift
for (k=0;k<40;k++) // scan whole array
{
if (buffer1[k] & 0x80) // test MSB of each byte
bit_mask[k+8] = 0x01; // taking the address of the next parallel byte
}
for (k=0;k<40;k++) // shift every byte
buffer1[k]<<=1;
for (k=0;k<40;k++) // copy the carried bit to the parallel byte
buffer1[k]|=bit_mask[k];
for (k=0;k<40;k++) // clear bit_mask content for the next test
bit_mask[k]=0;
}