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
Restricted to the x86 platform, you can use the PEXT instruction. It is part of the BMI2 instruction set extension on newer processors.
Use 32-bit instructions in a row and then merge the results in one value with shifts.
This is probably the optimal approach on Intel processors, but the disadvantage is that this instruction is slow on AMD Ryzen.