bytes to Integer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Govind

    #1

    bytes to Integer

    Hi All ,
    I have converted a Integer to Byte and Written in to the file. After
    that i read the file byte by byte then I want to Convert th Bytes to Integer
    .. If any method is available to convert Bytes to Integer pls Let me Know.

    Regards,
    Govind.


  • Jon Skeet

    #2
    Re: bytes to Integer

    Govind <govind_k@inter worldgroup.com> wrote:[color=blue]
    > I have converted a Integer to Byte and Written in to the file. After
    > that i read the file byte by byte then I want to Convert th Bytes to Integer
    > . If any method is available to convert Bytes to Integer pls Let me Know.[/color]

    Look at BitConverter.To Int32.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Eric Eggermann

      #3
      Re: bytes to Integer


      "Govind" <govind_k@inter worldgroup.com> wrote in message
      news:%23X3JYmKX DHA.2256@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Hi All ,
      > I have converted a Integer to Byte and Written in to the file.[/color]
      After[color=blue]
      > that i read the file byte by byte then I want to Convert th Bytes to[/color]
      Integer[color=blue]
      > . If any method is available to convert Bytes to Integer pls Let me Know.[/color]

      Hello,
      Byte to integer conversion can be implicit. In other words, you don't need
      to write special code.

      byte b = Convert.ToByte( "5", 10);
      //Change it to an integer.
      int i = b;
      Console.WriteLi ne(i); // prints 5

      You can look at the convert class, which is what I used to put the string
      "5" into a byte, but you don't need it to convert a byte to an integer.

      But maybe that's not what you need. Maybe you should look up serialization
      in the help files. You don't have to convert stuff byte by byte yourself to
      write it to a binary file.

      HTH
      Eric


      Comment

      • Jon Skeet

        #4
        Re: bytes to Integer

        "Eric Eggermann" <<none>> <"Eric Eggermann" <<none>>> wrote:[color=blue]
        > Byte to integer conversion can be implicit. In other words, you don't need
        > to write special code.[/color]

        Yes he does. Reread the original post - he's not trying to convert a
        *single* byte into an integer, but an array of bytes (presumably 4)
        into an integer. Fortunately, BitConverter.To Int32 has this covered.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...