Android Question checksum ccitt

rkxo

Active Member
Licensed User
Longtime User
Hi,
Someone could convert this function to b4a?
CRC CCITT:
uint16_t frameHandler::CalculateCRC(uint8_t* ptrBuffer, int32_t size) {

    uint16_t crc = 0;

    uint32_t x = 0;

    uint8_t i;


    while (--size >= 0){

        crc = crc ^ (int)ptrBuffer[x++] << 8;

        for (i = 0; i < 8; ++i){

               if (crc & 0x8000) crc = crc << 1 ^ 0x1021; //  CCITT POLYNOMIAL



               else             crc = crc << 1;

        }

    }

    return crc;

}

I have converted it to vb.net but i don't know if its right
VB.NET Conversor:
Public Function CalculateCRC(ByVal ptrBuffer() As Byte, ByVal size As Integer) As UShort

        Dim crc As UShort = 0

        Dim x As UInteger = 0

        Dim i As Byte


        size -= 1


        Do While size >= 0

            crc = (crc Xor CInt(ptrBuffer(x)) << 8)

            x += 1

            For i = 0 To 7

                If (crc And &H8000) <> 0 Then

                    crc = (crc << 1 Xor &H1021) ' POLINOMIO CCITT

                Else

                    crc = (crc << 1)

                End If

            Next i

            size -= 1

        Loop

        Return crc

    End Function

Thanks
 
Last edited:
Top