Ver Mensaje Individual
  #1599  
Antiguo 23-09-2021
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 125
Reputación: 3
Ramon88 Va por buen camino
Termino de encontrar una función en .Net que si no me equivoco funciona bien.
Código:
    Function CRC_8(ByVal Txt As String) As Byte
        Dim Poly() As Byte = {1, 0, 0, 0, 0, 0, 1, 1, 1}
        Dim MessageBits As New List(Of Byte)
        Dim MsgBinString As String = ""
        'Compute the message binary
        For Each C As Char In Txt
            Dim S As String = Convert.ToString(Asc(C), 2)
            If S.Length < 8 Then S = New String("0"c, 8 - S.Length) & S

            MsgBinString &= S
        Next
        For Each C As Char In MsgBinString
            If C = "0"c Then MessageBits.Add(0) Else MessageBits.Add(1)
        Next
        'add 8 bits set to zero
        MessageBits.AddRange(New Byte() {0, 0, 0, 0, 0, 0, 0, 0})
        'compute CRC
        While MessageBits.Count > 8
            If MessageBits(0) = 0 Then
                MessageBits.RemoveAt(0)
                Continue While
            End If
            For x = 0 To 8 '<--9 bits
                MessageBits(x) = MessageBits(x) Xor Poly(x)
            Next
        End While
        'put the result in byte format and return
        Dim Result As Byte = 0
        For x = 0 To 7
            Result = Result Or (MessageBits(7 - x) << x)
        Next
        Return Result
    End Function
Responder Con Cita