If the result should be B01100001 , then byte 0 is MSB (the most significant bit), not byte 7 ...
char line[8] = { 0, 1, 1, 0, 0, 0, 0, 1 }; unsigned char b = 0; for ( int ii = 0; ii < 8; ii++ ) { b <<= 1; b |= line[ii]; }
Other answers that I saw, if I read them correctly, put the MSB on byte 7.
EDIT: fixed quotes; I have not read it before.
source share