I recently started C and for some reasons I couldn't get this line c |= 1 << i;
the purpose of this function I found online is to get the least significant bit from an array and then combine it, and return as a byte.
unsigned char getlsbs(unsigned char* p)
{
int i;
unsigned char c = 0;
for(i = 0; i < 8; i++)
{
int a = p[i] & 1;
if(a)
{
c |= 1 << i;
}
}
return c;
}
c |= 1 << i; would be the same as c = c | 1 << i; correct?
Could anyone explain with the example in 1s and 0s? I think it will be very helpful. Thanks!