+ 1

How to write bits of the variable into the array, bit after bit

fo example i've got variable unsigned char data0b00101101 and i want an array that would contain this bits.

21st Sep 2017, 10:23 AM
anton599
anton599 - avatar
3 Answers
+ 12
For all the characters inside the array: if the character is numerical: extract and store into another array/string. else skip the character and proceed.
21st Sep 2017, 10:49 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
int array[8]; unsigned i; unsigned char data; /*define your data here */ for(i = 7; i < 8; --i) array[i] = (data>>(7 - i))&1;
21st Sep 2017, 11:00 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
no, i can't, I need to write on c, but not cpp
25th Sep 2017, 7:44 AM
anton599
anton599 - avatar