I’ve got a long[] which I’d like to read two bits at a time. My data are the binary numbers 00,01,10, and 11 concatenated end to end, stuffed in a long, and then stuffed in an array.
I’ll be reading a long stretch of this data at once, possibly starting halfway through, and it seems like it would make more sense to read straight from memory, two bytes at a time, rather than iterating through the long[] and pulling two bits at a time with a mask.
I can’t seem to figure out how I’d go about this, and I’ve never been great with directly accessing memory (since I was brought up on java).
I’ve tried instantiating an array
unsigned long t[5];
t[0] = 4294967295;
t[1] = 0;
t[2] = 4294967294;
t[3] = 4294967296;
t[4] = 1;
and then printing *(&t) and *(&t+1), but the plus one of course knows that it’s the size of long and goes adds the appropriate value.
Use a pointer to a byte-sized data type. Try this:
And use p pointer.