static void Main(string[] args)
{
var ss = "01 03 1E 8B 2E 0D 8B 74 92 FD 01 B3 10 00 22 21 01 00 00 00 00 00 00 00 00 00 98 92 98 E0 0F 97";
var dataBuff = strToToHexByte(ss);
var count = 0;
count = dataBuff[4]; count &= 0x01; count <<= 8;
count |= dataBuff[3];
Console.WriteLine("速度:"+count.ToString());
count = dataBuff[7]; count <<= 8;
count |= dataBuff[6]; count <<= 8;
count |= dataBuff[5];
Console.WriteLine("計數器1:" + count.ToString());
count = dataBuff[28]; count <<= 8;
count |= dataBuff[27]; count <<= 8;
count |= dataBuff[26];
Console.WriteLine("計數器1設定數:" + count.ToString());
}
private static byte[] strToToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
uj5u.com熱心網友回復:
先轉VB.NetImports System
Namespace test
' Token: 0x02000002 RID: 2
Public Module program
' Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
Public Sub Main(args As String())
Dim hexString As String = "01 03 1E 8B 2E 0D 8B 74 92 FD 01 B3 10 00 22 21 01 00 00 00 00 00 00 00 00 00 98 92 98 E0 0F 97"
Dim array As Byte() = program.strToToHexByte(hexString)
Dim num As Integer = CInt(array(4))
num = num And 1
num <<= 8
Console.WriteLine("速度:" + (num Or CInt(array(3))).ToString())
num = CInt(array(7))
num <<= 8
num = num Or CInt(array(6))
num <<= 8
Console.WriteLine("計數器1:" + (num Or CInt(array(5))).ToString())
num = CInt(array(28))
num <<= 8
num = num Or CInt(array(27))
num <<= 8
Console.WriteLine("計數器1設定數:" + (num Or CInt(array(26))).ToString())
End Sub
' Token: 0x06000002 RID: 2 RVA: 0x000020F8 File Offset: 0x000002F8
Private Function strToToHexByte(hexString As String) As Byte()
hexString = hexString.Replace(" ", "")
Dim flag As Boolean = hexString.Length Mod 2 <> 0
If flag Then
hexString += " "
End If
Dim array As Byte() = New Byte(hexString.Length / 2 - 1) {}
For i As Integer = 0 To array.Length - 1
array(i) = Convert.ToByte(hexString.Substring(i * 2, 2), 16)
Next
Return array
End Function
End Module
End Namespace
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/159728.html
標籤:VB基礎類
上一篇:DevOps實踐指南(5-8)
