I have an array of char (usually thousands of bytes long) read from a file, all composed of 0 and 1 (not \'0\' and \'1\', in which case I could use strtoul
). I want
Bit shifting is the simplest way to go about this. Better to write code that reflects what you're actually doing rather than trying to micro-optimize.
So you want something like this:
char bits[32];
// populate bits
uint32_t value = 0;
for (int i=0; i<32; i++) {
value |= (uint32_t)(bits[i] & 1) << i;
}