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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Convert an array of byte into other types

Convert an array of byte into other types

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structuresperformancehelp
5 Posts 2 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.
  • T Offline
    T Offline
    thanh_bkhn
    wrote on last edited by
    #1

    Hi all, I want to write a little function in VB.NET. It must convert an array of byte ( ex: data as Byte() ) into other types like Integer, Float, Double... I think the fastest way is copy memory like in C, but VB.NET does not support any such method. Any help is appreciated, thank you.

    T 1 Reply Last reply
    0
    • T thanh_bkhn

      Hi all, I want to write a little function in VB.NET. It must convert an array of byte ( ex: data as Byte() ) into other types like Integer, Float, Double... I think the fastest way is copy memory like in C, but VB.NET does not support any such method. Any help is appreciated, thank you.

      T Offline
      T Offline
      thanh_bkhn
      wrote on last edited by
      #2

      Hi all, I just found the method to convert to Integer types like Int16, Int32, Int64 by Marshal class: Use the Copy method to copy the data in Byte() into an IntPtr pointer, after that copy the pointer into an integer variable by the ReadInt32 method. But the problem still exists: the Marshal class does not have any method to copy a pointer into a Single or Double variable. Anyone have suggestion?

      D 1 Reply Last reply
      0
      • T thanh_bkhn

        Hi all, I just found the method to convert to Integer types like Int16, Int32, Int64 by Marshal class: Use the Copy method to copy the data in Byte() into an IntPtr pointer, after that copy the pointer into an integer variable by the ReadInt32 method. But the problem still exists: the Marshal class does not have any method to copy a pointer into a Single or Double variable. Anyone have suggestion?

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        The .NET Framework has beaten you to this little project. Check out the BitConverter[^] class. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          The .NET Framework has beaten you to this little project. Check out the BitConverter[^] class. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          T Offline
          T Offline
          thanh_bkhn
          wrote on last edited by
          #4

          Thank you, The BitConverter class meets most of my needs, except the String type :)

          D 1 Reply Last reply
          0
          • T thanh_bkhn

            Thank you, The BitConverter class meets most of my needs, except the String type :)

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            StringBuilder[^] class RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            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