So, bit fields. In particular, large bit fields. I understand how to manipulate individual values ββin a bit field, but how will I do this on a large set, for example, say:
uint[] bitfield = new uint[4] { 0x0080000, 0x00FA3020, 0x00C8000, 0x0FF00D0 };
The specific problem I am facing is a left and right shift going through the entire array. So, for example, if I made >> 4 in the above array, I would end with:
uint[4] { 0x0008000, 0x000FA302, 0x000C800, 0x00FF00D };
Now the (overly) simplified algorithm here might look something like this (this is where I find the code on the fly):
int shift = 4; for (int i = 0; i <= shift; i++) { for (int j = bitfield.GetUpperBound(0); j > 0; j--) { bitfield[j] = bitfield[j] >> 1; bitfield[j] = bitfield[j] + ((bitfield[j-1] & 1) << (sizeof(uint)*8)); } bitfield[0] = bitfield[0] >> 1; }
Is there anything built-in that can make it easier to work with such data?
source share