0
can tell me if there is any sql function that calculates CRC16, the calculation method is listed as "CRC-CCITT (0xFFFF)".
CRC-CCITT (0xFFFF) -> polynomial: x 16 + x 12 + x 5 + 1
I tried to create the function below, but it is not calculating in the right way:
(
@input varchar(max)
)
RETURNS int
WITH SCHEMABINDING
AS
BEGIN
DECLARE @crc bigint = 0xffff
, @result int
;
SELECT @crc = dbo.CRC16calc(@crc, Ascii(Substring(@input, v.id, 1)))
FROM dbo.IndexTable(1, LEN(@input)) AS v
ORDER
BY v.Id
;
SET @result = (CONVERT(int, CONVERT(VARBINARY(4), ~@crc))) ;
RETURN @result ;
END
Just to confirm the expected result ... if you enter the string "123456789", the expected result is the integer number 10673 ? ( i.e., "0x29B1" in hexadecimal ) ?
– siga0984
I don’t know Gabriel, that’s an opinion but, it wouldn’t be easier to do it in a language in . net, which should many examples and code ready, install the dll on the server and import the Function? code
sql
was not done well for these things, it is like wanting to program a high performance game incobol
, That’s not what the language was made for. I’ve had code like this with encryption algorithms in older versions of sql, and it worked well a code in . net imported as a Function– Ricardo Pontual