To be on the same page, let's say sizeof (int) = 4 and sizeof (long) = 8.
Given an array of integers, what would be an effective method for logical bitwise shifting the array left or right?
I am considering a helper variable, such as long, that will calculate the bit-shift for the first pair of elements (index 0 and 1) and set the first element (0). Continuing in this way the bitrate for the elements (index 1 and 2), there will be a computer, and then index 1 will be set.
I think this is actually a pretty effective method, but there are drawbacks. I can not beat more than 32 bits. I think using a few helper variables will work, but I foresee recursion somewhere along the line.
c arrays bit-manipulation bit-shift
snap
source share