.net - (C#) Is there a way to set the value of a single bit through pointers? -
What do I mean: Imagine that we have an 8 byte variable with a high value and low value. I can make a pointer point between the upper 4 bytes and the other point at 4 bytes, and set / retain my values without problems. Now, is there any way to obtain / determine the values of any thing compared to any byte? If instead of dividing it into two 4 bytes "Variables", I would like to consider eight 1 byte variable, but I can use a bool, but in C # there are no defined small variables. Could it possibly be possible to divide only 16 with the pointer? Or even 32, 64? Would not it be right?
This is a very academic question, I know that it can be achieved with otherwise bitsfifing, unions (Stract. Good) etc. Thanks!
No, the C # field does not support fields and a byte is the minimum amount of addressable memory You can manually provide properties that change one or several specific bits, but you must pay packing / unpacking logic itself:
Public Bull Bit 5 {get {return ( Field & 32)! = 0; } Set {if (field) field | = 32; Other fields & amp; = ~ 32; }}
By the way, I do not know how you can get it LayoutCind.Explicit
as the minimum FieldOffset
You can specify a byte .
In the form of a side note, even C ++ which can do this with the bit field, hide the bitsword tricks and the compiler does it instead of you There is no way that you can at least take the memory from a byte on a x86 architecture in a register.
Comments
Post a Comment