Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert byte array to a single 2

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
I'm getting bytes from a device which is in a reverse order, I need to reverse the bytes and convert that from a byte array to a single datatype.

This will give me the reverse of the byte order

Dim ucConversion(3) as byte
Dim ucNodePacket(26) as byte

For i = 0 to 3
ucConversion(i) = ucNodePacket(13 - i)
next

Now I need to convert the ucConversion(bytearray) to a single data type, this is where I need help.

Thanks

 
Take a look at the BitConverter class.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Here is some sample code that may help

Option Strict Off
Option Explicit On

Imports System.IO
Imports System.Text
Imports System.Buffer

Dim bDesc(), bPtid(), bData() As Byte
Dim dNo, dEa, dEl As Double
Dim sXval As Single

......Open binary file with BinaryReader - call it BR

bData = BR.ReadBytes(80) 'Read 80 bytes into byte array with BinaryReader

sXval = BitConverter.ToSingle(bData, 5) 'Starting at and including byte 5 read & cvt to single
dNo = BitConverter.ToDouble(bData, 48) 'Starting at and including byte 48 read & cvt to double
dEa = BitConverter.ToDouble(bData, 56)
dEl = BitConverter.ToDouble(bData, 64)


Regards,
Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top