how to make a bit-set/byte-array conversion in c
问题 Given an array, unsigned char q[32]="1100111..." , how can I generate a 4-bytes bit-set, unsigned char p[4] , such that, the bit of this bit-set, equals to value inside the array, e.g., the first byte p[0]= "q[0] ... q[7]"; 2nd byte p[1]="q[8] ... q[15]", etc. and also how to do it in opposite, i.e., given bit-set, generate the array? my own trial out for the first part. unsigned char p[4]={0}; for (int j=0; j<N; j++) { if (q[j] == '1') { p [j / 8] |= 1 << (7-(j % 8)); } } Is the above right?