[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: CRC16 ccitt 1021 - Part 2
- From: Jonathan Goble <jcgoble3@...>
- Date: Thu, 24 Oct 2019 00:17:45 -0400
On Thu, Oct 24, 2019 at 12:03 AM Russell Haley <russ.haley@gmail.com> wrote:
>
> Results:
>
> C:\Users\russh\projects\NLuaSerialScripts> lua .\test-crc.lua
> Lua Calling C hash:
> -16032.0
> C on packed string
> -16032.0
> Lua Clark Li:
> Disabled, my variant didn't work
> Lua converted C:
> 49504
>
> Any ideas why I get a different number? All input greatly appreciated.
>
> Russ
You're actually getting the same number. The difference is that the
original C code is using signed 16-bit integers and 49504 has an MSB
of 1, so two's complement is used, while Lua is using 64-bit integers,
so two's complement doesn't come into play (MSB is 0). If you put
49504 into an unsigned 16-bit integer in C and then cast it to signed,
the result will be -16032.