如何在数据中取三(3)个字节然后解码 [英] How take three (3) bytes in a Data and then decode
问题描述
大家好,
我有一个包含几个字节的变量。度量由3个字节组成。我需要恢复每3个字节编码的所有度量。我该怎么做?
Hi everybody,
I have a variable that contain several bytes. A measure is compose by 3 bytes. I need to recover all the measures that are coded every 3 bytes. How i can do that?
Dim converter As New Systeme.Data.Records.RecordsDataToRecordsCollectionConverter(Monitoring)
Dim recordsCollection1 As Systeme.Devices.Records.IRecordsCollection = converter.convert(Data1)
For Each record As Systeme.IRecord In recordsCollection1.recordsList
If record.recordType = Systeme.Interfaces.Devices.Records.RecordType.TrackMeasure Then
Dim recordMeasure As Systeme.Interfaces.Devices.SpyRf.Records = TryCast(record, Systeme.Interfaces.Records)
End If
End For
所有信息都在Data1中。信息以字节为单位。我需要每3个字节有1个mesure。之前我需要将字节转换为字符串或双精度或Int。
有没有可以帮助我?
Thans
All information is in Data1. The information is in Bytes. I need to take every 3 bytes to have 1 mesure. Before i need to convert the bytes to string or double or Int.
Does any can help me?
Thans
推荐答案
好的,那么Data1是一个字节数组?怎么样:
Ok, so Data1 is a byte array? How about this:
Dim ms As New MemoryStream(Data1)
Dim buffer(2) As Byte
For count As Integer = 0 to (Data1.Length / 3) -1
ms.Read(buffer, 0, 3)
Next
内存流将关闭3个字节并用它们填充缓冲区,直到已经读取了Data1中的所有字节。
- Pete
The memorystream will pull 3 bytes off and fill buffer with them until all the bytes in Data1 have been read.
- Pete
这篇关于如何在数据中取三(3)个字节然后解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!