高手帮我将此段VB程序翻译成C语言

kerrygood kerrygood 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
小弟乃VB菜鸟,只学过C语言。不懂,尤其是VB的运算符,很头疼。下面是代码
Public Function crc16z(ByVal txt As String, ByVal lon As Long) As Long
Dim flag As Long
Dim crc As Long
Dim car As Integer
Dim bit As Integer
Dim test As String
crc = &HFFFF&
For car = 1 To lon Step 2
crc = crc Xor getHex(Mid(txt, car, 2))
For bit = 0 To 7
flag = crc And 1&
crc = crc \ 2&
If flag = 1 Then crc = crc Xor &HA001&
Next
Next
crc16z = Int(crc And &HFFFF&)
End Function


Public Function getHex(ByVal inputString) As Byte
Dim ib As String
Dim returnValue
returnValue = 0
ib = UCase(Mid(inputString, 1, 1))
If ib = "0" Then returnValue = 0
If ib = "1" Then returnValue = 16
If ib = "2" Then returnValue = 32
If ib = "3" Then returnValue = 48
If ib = "4" Then returnValue = 64
If ib = "5" Then returnValue = 80
If ib = "6" Then returnValue = 96
If ib = "7" Then returnValue = 112
If ib = "8" Then returnValue = 128
If ib = "9" Then returnValue = 144
If ib = "A" Then returnValue = 160
If ib = "B" Then returnValue = 176
If ib = "C" Then returnValue = 192
If ib = "D" Then returnValue = 208
If ib = "E" Then returnValue = 224
If ib = "F" Then returnValue = 240
ib = UCase(Mid(inputString, 2, 1))
If ib = "0" Then returnValue = returnValue + 0
If ib = "1" Then returnValue = returnValue + 1
If ib = "2" Then returnValue = returnValue + 2
If ib = "3" Then returnValue = returnValue + 3
If ib = "4" Then returnValue = returnValue + 4
If ib = "5" Then returnValue = returnValue + 5
If ib = "6" Then returnValue = returnValue + 6
If ib = "7" Then returnValue = returnValue + 7
If ib = "8" Then returnValue = returnValue + 8
If ib = "9" Then returnValue = returnValue + 9
If ib = "A" Then returnValue = returnValue + 10
If ib = "B" Then returnValue = returnValue + 11
If ib = "C" Then returnValue = returnValue + 12
If ib = "D" Then returnValue = returnValue + 13
If ib = "E" Then returnValue = returnValue + 14
If ib = "F" Then returnValue = returnValue + 15
getHex = returnValue
End Function
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
kerrygood
VB基础类 7,788 成员 197,583 内容