Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Read from Byte Array

Read from Byte Array

Scheduled Pinned Locked Moved C#
questiondata-structures
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DJ245
    wrote on last edited by
    #1

    Dear All, How can i read values from Byte Array? Regards, DJ.

    P M B 3 Replies Last reply
    0
    • D DJ245

      Dear All, How can i read values from Byte Array? Regards, DJ.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The easiest way to read the data is to loop over the array. Here's a typical method for doing this:

      for (int i = 0; i < myArray.Count; i++)
      {
      byte value = myArray[i];
      }

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      1 Reply Last reply
      0
      • D DJ245

        Dear All, How can i read values from Byte Array? Regards, DJ.

        M Offline
        M Offline
        Mario Majcica
        wrote on last edited by
        #3

        Next time consider this: http://tinyurl.com/5vb53y9[^] However this is a good point where to start http://www.dotnetperls.com/byte-array[^] Take care

        1 Reply Last reply
        0
        • D DJ245

          Dear All, How can i read values from Byte Array? Regards, DJ.

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          You can read larger base types from a byte array with BitConverter[^].

          D D 2 Replies Last reply
          0
          • B BobJanova

            You can read larger base types from a byte array with BitConverter[^].

            D Offline
            D Offline
            dybs
            wrote on last edited by
            #5

            Be careful when using BitConverter. It uses the endianness of your CPU, so if you're byte array is coming from a hardware device with a different endianness, your BitConverter results will be messed up. See BitConverter.IsLittleEndian[^] Dybs

            The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

            B 1 Reply Last reply
            0
            • D dybs

              Be careful when using BitConverter. It uses the endianness of your CPU, so if you're byte array is coming from a hardware device with a different endianness, your BitConverter results will be messed up. See BitConverter.IsLittleEndian[^] Dybs

              The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              Indeed. Most platforms agree on endianness but particularly if you deal with embedded systems this can be a concern.

              1 Reply Last reply
              0
              • B BobJanova

                You can read larger base types from a byte array with BitConverter[^].

                D Offline
                D Offline
                DJ245
                wrote on last edited by
                #7

                Actually i don't want its size. I need to get the value. When i iterating it displays the size. How can i get the value behind each array item?

                L 1 Reply Last reply
                0
                • D DJ245

                  Actually i don't want its size. I need to get the value. When i iterating it displays the size. How can i get the value behind each array item?

                  L Offline
                  L Offline
                  lukeer
                  wrote on last edited by
                  #8

                  Since your question mentioned a byte array, the size of each item is 1 byte. Pete O'Hanlon mentioned the item count within the array. One could call that a size, too.

                  DJ245 wrote:

                  When i iterating it displays the size.

                  What size exactly do you mean by this?

                  DJ245 wrote:

                  How can i get the value behind each array item?

                  Each item's value is exactly what Pete O'Hanlon's answer is concerning with.

                  Ciao, luker

                  D 1 Reply Last reply
                  0
                  • L lukeer

                    Since your question mentioned a byte array, the size of each item is 1 byte. Pete O'Hanlon mentioned the item count within the array. One could call that a size, too.

                    DJ245 wrote:

                    When i iterating it displays the size.

                    What size exactly do you mean by this?

                    DJ245 wrote:

                    How can i get the value behind each array item?

                    Each item's value is exactly what Pete O'Hanlon's answer is concerning with.

                    Ciao, luker

                    D Offline
                    D Offline
                    DJ245
                    wrote on last edited by
                    #9

                    Please check the screenshot http://doubts.posterous.com/bytearray-doubt[^] Actual value in the byteArray[0] is Name of an employee, [1] is code and son on... When iterating it returns only its size.. How can i get the Name of Employee from byteArray[0]?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups