how to convert bytes array?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U3VzaGlTZWFu?=

    #1

    how to convert bytes array?

    Hello, I have a question.
    byte[] network = new byte[100];
    And I know what in this byte array in position from 4 to 8 it is long value,
    and from 10 to 12 is it ushort type.

    I need do something like this
    long val1 = (long)network[4-8];
    ushort val2 = (ushort )network[10-12];

    So I need get few bytes from some position and convert them to some value
    type.
    How can i do this?
  • Peter Duniho

    #2
    Re: how to convert bytes array?

    SushiSean wrote:
    [...]
    So I need get few bytes from some position and convert them to some value
    type.
    How can i do this?
    You may find the BitConverter class useful for the purpose.

    Comment

    • Michael C

      #3
      Re: how to convert bytes array?

      "SushiSean" <SushiSean@disc ussions.microso ft.comwrote in message
      news:6F9BFCA5-53E5-45AA-A227-4D032D2640A4@mi crosoft.com...
      Hello, I have a question.
      byte[] network = new byte[100];
      And I know what in this byte array in position from 4 to 8 it is long
      value,
      and from 10 to 12 is it ushort type.
      >
      I need do something like this
      long val1 = (long)network[4-8];
      ushort val2 = (ushort )network[10-12];
      Note that the value is in bytes 4 to 7 and 10 to 11.

      Michael


      Comment

      Working...