vb.net CRC计算-----CRC_CCITT

前端之家收集整理的这篇文章主要介绍了vb.net CRC计算-----CRC_CCITT前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    Public Function CRC_CCITT(ByVal Data() As Byte) As String

        Dim crc As UShort
        Dim i As Byte,j As Integer
        Dim crch As String,crcl As String

        crc = 0
        For j = 0 To Data.Length - 1
            i = &H80
            Dim val As UShort = Data(j)
            val = val << 8
            crc = crc Xor val

            While (i <> 0)
                If (crc And &H8000) <> 0 Then
                    crc = crc << 1
                    crc = crc Xor &H1021
                Else
                    crc = crc << 1
                End If
                i = i / 2
            End While
        Next j

        crch = Hex(Fix(crc / 256))
        If Len(crch) = 1 Then crch = "0" & crch
        crcl = Hex(crc Mod 256)
        If Len(crcl) = 1 Then crcl = "0" & crcl
        CRC_CCITT = crch & crcl

    End Function

猜你在找的VB相关文章