Guest User

C# 3 byte Ints

a guest
Feb 27th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. [StructLayout(LayoutKind.Explicit)]
  2. struct OddUnion
  3. {
  4. /* The 32-bit integer value */
  5. [FieldOffset(0)]
  6. public int IntegerValue;
  7.  
  8. /* The bytes that overlap with it */
  9. [FieldOffset(0)]
  10. public byte Byte1;
  11. [FieldOffset(1)]
  12. public byte Byte2;
  13. [FieldOffset(2)]
  14. public byte Byte3;
  15. [FieldOffset(3)]
  16. public byte Byte4;
  17. }
  18.  
  19. OddUnion myOddUnion;
  20. myOddUnion.IntegerValue = 4096;
  21. Byte secondByte = myOddUnion.Byte1;
  22.  
  23. int binary
  24. 0 00000000
  25. 1 00000001
  26. ...
  27. 127 01111111
  28. 128 00000001 10000000
  29. 129 00000001 10000001
  30. ...
  31. 255 00000001 11111111
  32. 256 00000010 10000000
  33. ...
  34. 16383 01111111 11111111
  35. 16384 00000001 10000000 10000000
Add Comment
Please, Sign In to add comment