I'm processing large amounts of data to parse out data bit-wise. Essentially I have a number that represents 16 bits and I need to get certain bits out as a number. I've tried this two ways:
Convert number to boolean array
Get array subset for bits I need
Convert subset back to a number
This method works fine, but cant keep up on slower computers due to the amount of data to process. I figured converting back and forth between arrays and numbers was not very efficient, so I tried using bit masks:
AND number with bit mask to elimiate bits i dont need
Left shift if necessary using 2**n scaling
This method also works fine, but is not measurably faster than the other method. I put timers in the processing loops for both and there is no noticeable difference.
Is there a better way to do this?
TIA,
Bill F