以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 16进制转换问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=170609) |
-- 作者:shyilin6 -- 发布时间:2021/8/1 11:31:00 -- 16进制转换问题 下面这些怎么实现,用步长值为4 【发送1】 00 00 00 05 00 00 00 09【发送2】 00 00 00 0A 00 00 00 0E 【发送3】 00 00 00 0F 00 00 00 13 【发送4】 00 00 00 14 00 00 00 18 。。。。 连续发送16进制要怎么写? 思路: 循环出用10进制转16进制 发送之前替代进去对应位置? 这样会遇到转换的时候出现前面是0就消失 |
-- 作者:有点蓝 -- 发布时间:2021/8/1 20:10:00 -- 没看懂,贴出代码举例说明一下 |
-- 作者:shyilin5 -- 发布时间:2021/8/3 20:12:00 -- Dim st As String ="" Dim i As Integer For i = 1 To 40 Step 5 If st>"" Then st = st & "," & DecToHex(i) Else st=DecToHex(i) End If Next Output.Show(st) 结果是:1,6,B,10,15,1A,1F,24 红字的0没了 有什么办法解决?
|
-- 作者:李连山 -- 发布时间:2021/8/3 20:31:00 -- Dim st As String ="" Dim i As Integer For i = 1 To 1140 Step 5 If st > "" Then If DecToHex(i).Length = 1 st = st & "," & "0" & DecToHex(i) Else st = st & "," & DecToHex(i) End If Else If DecToHex(i).Length = 1 st = "0" & DecToHex(i) Else st = DecToHex(i) End If End If Next |
-- 作者:shyilin5 -- 发布时间:2021/8/3 20:54:00 -- 只能这样了,谢谢了 |
-- 作者:有点蓝 -- 发布时间:2021/8/3 21:07:00 -- 或者 Dim st As String ="" Dim i As Integer For i = 1 To 40 Step 5 If st>"" Then st = st & "," & cstr(DecToHex(i)).PadLeft(2,"0") Else st=cstr(DecToHex(i)).PadLeft(2,"0") End If Next Output.Show(st) |
-- 作者:shyilin -- 发布时间:2021/8/4 10:15:00 -- Dim st As String ="" Dim st1 As String ="0000000000000000" Dim i As Integer Dim i2 As Integer=0 For i = 0 To 40 Step 5 Dim i1 As Integer =8-cstr(DecToHex(i)).PadLeft(2,"0").Length If i2=0 Then st= st1.Remove(i1,cstr(DecToHex(i)).PadLeft(2,"0").Length) st= st.Insert(i1,cstr(DecToHex(i)).PadLeft(2,"0")) End If i2=i2+1 If i2=1 Then Continue For End If If i2=2 Then Dim i3 As Integer =16-cstr(DecToHex(i)).PadLeft(2,"0").Length st= st.Remove(i3,cstr(DecToHex(i)).PadLeft(2,"0").Length) st= st.Insert(i3,cstr(DecToHex(i)).PadLeft(2,"0")) i2=0 End If Output.Show(st) st1 ="0000000000000000" Next 结果: 00000000000000050000000A0000000F 0000001400000019 0000001E00000023 我要的结果是 0000000000000005 000000060000000B 0000000C00000011 0000001200000017 请老师帮忙看看呢 |
-- 作者:有点蓝 -- 发布时间:2021/8/4 10:23:00 -- Dim st As String ="" Dim i As Integer For i = 1 To 40 Step 5 If st>"" Then st = st & cstr(DecToHex(i)).PadLeft(8,"0") Output.Show(st) st = "" Else st = cstr(DecToHex(i)).PadLeft(8,"0") End If Next
|
-- 作者:shyilin -- 发布时间:2021/8/4 10:55:00 -- 您的结果是: 0000000100000006 0000000B00000010 000000150000001A 0000001F00000024 不对 0000000000000005 000000060000000B0000000C00000011 0000001200000017 红色是 上一次+1
|
-- 作者:有点蓝 -- 发布时间:2021/8/4 10:58:00 -- 自己补上+1的代码 |