How do I inspect data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarDude
    New Member
    • Feb 2010
    • 7

    How do I inspect data?

    Hello, I am having a problem marshaling data between managed and unmanaged code. So I need to inspect the data at the byte level. What I need to do is store a number, say 8 into a 4-byte integer then copy it to an array bytArray(4) and compare those bytes with other data. I also need to set up the same array and copy it to an integer variable.

    Can this be done? And if so does anyone know how?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The value of 8 wouldn't need to be 4 bytes. One would due just fine so long as you don't need to send a value greater than 255.

    The first byte would be the number of 1's - This would be set to 8.
    The second byte would be the number of 256's
    3rd would be number of 65536's
    4th would be number of 16777216's

    Anyway... Read up on the BitConverter at MSDN This does what you need.

    Comment

    • MarDude
      New Member
      • Feb 2010
      • 7

      #3
      Excellent!! Thank you that is exactly what I needed!!

      Just wanted to note you do need 4 bytes if you are storing 8 as a 32 bit integer. And yes that is a waste (waste of memory, but saving of CPU cycles), but if a structure has the member defined as an integer or a function that you did not write returns an integer you have no control over it. Then there's the issue of -8, which I just found out is stored as (248, 255, 255, 255) when typed as an integer

      I am having a serious scanner issue and it looks like I have to examine the memory and perhaps manually marshal the data since 8 forums I posted the question to have no clue as to how to solve it (or I can not explain it properly). But with Marshal.ReadInt 32 and BitConverter.Ge tBytes I hope I can figure out what is going wrong.

      Comment

      Working...