I am looking to encapsulate all this data within one "long" (64-bit integer).
You can use StructLayoutAttribute
with LayoutKind.Explicit
and then decorate fields with FieldOffsetAttribute
specifying the exact position.
I want properties to get and set each piece of data using bit shifting, etc... (I have never done this).
Then use shift left (<<
), shift right (>>
) and masking (and &&
to extract / or ||
to write (don't forget about any non-zero bits in the target byte)) with 0xff
to separate individual bytes. Read more about bitwise operations here.
Would this save space? Would it increase processing speed?
Did you measure it? Did you discover a performace / memory consuption problem? If yes, go optimize it. If not, do not do premature optimizations. In other words, don't blindly try without measuring first.