C#代码转换成Vb6.0

hbqc_zh 2020-09-16 05:24:58
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;
}
...全文
290 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
data-v-165b75c4 2020-09-17
  • 打赏
  • 举报
回复
先转VB.Net
Imports 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

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧