I have Sql Code that converts input to CRC-32 Need help to convert CRC-32 to CRC-16 is there any other resource available. below is my SQl Please help I need 4 digit output code
DECLARE @input VARCHAR(50)
SET @input = '0002020102110202000424PK79013914031004'
SET NOCOUNT ON
DECLARE
@crc bigint = 0xFFFF,
@Lookup varbinary(2048) = '0x00000x10210x20420x30630x40840x50a50x60c60x70e70x81080x91290xa14a0xb16b0xc18c0xd1ad0xe1ce0xf1ef0x12310x02100x32730x22520x52b50x42940x72f70x62d60x93390x83180xb37b0xa35a0xd3bd0xc39c0xf3ff0xe3de0x24620x34430x04200x14010x64e60x74c70x44a40x5485
0xa56a0xb54b0x85280x95090xe5ee0xf5cf0xc5ac0xd58d
0x36530x26720x16110x06300x76d70x66f60x56950x46b4
0xb75b0xa77a0x97190x87380xf7df0xe7fe0xd79d0xc7bc
0x48c40x58e50x68860x78a70x08400x18610x28020x3823
0xc9cc0xd9ed0xe98e0xf9af0x89480x99690xa90a0xb92b
0x5af50x4ad40x7ab70x6a960x1a710x0a500x3a330x2a12
0xdbfd0xcbdc0xfbbf0xeb9e0x9b790x8b580xbb3b0xab1a
0x6ca60x7c870x4ce40x5cc50x2c220x3c030x0c600x1c41
0xedae0xfd8f0xcdec0xddcd0xad2a0xbd0b0x8d680x9d49
0x7e970x6eb60x5ed50x4ef40x3e130x2e320x1e510x0e70
0xff9f0xefbe0xdfdd0xcffc0xbf1b0xaf3a0x9f590x8f78
0x91880x81a90xb1ca0xa1eb0xd10c0xc12d0xf14e0xe16f
0x10800x00a10x30c20x20e30x50040x40250x70460x6067
0x83b90x93980xa3fb0xb3da0xc33d0xd31c0xe37f0xf35e
0x02b10x12900x22f30x32d20x42350x52140x62770x7256
0xb5ea0xa5cb0x95a80x85890xf56e0xe54f0xd52c0xc50d
0x34e20x24c30x14a00x04810x74660x64470x54240x4405
0xa7db0xb7fa0x87990x97b80xe75f0xf77e0xc71d0xd73c
0x26d30x36f20x06910x16b00x66570x76760x46150x5634
0xd94c0xc96d0xf90e0xe92f0x99c80x89e90xb98a0xa9ab
0x58440x48650x78060x68270x18c00x08e10x38820x28a3
0xcb7d0xdb5c0xeb3f0xfb1e0x8bf90x9bd80xabbb0xbb9a
0x4a750x5a540x6a370x7a160x0af10x1ad00x2ab30x3a92
0xfd2e0xed0f0xdd6c0xcd4d0xbdaa0xad8b0x9de80x8dc9
0x7c260x6c070x5c640x4c450x3ca20x2c830x1ce00x0cc1
0xef1f0xff3e0xcf5d0xdf7c0xaf9b0xbfba0x8fd90x9ff8
0x6e170x7e360x4e550x5e740x2e930x3eb20x0ed10x1ef0'
SELECT @crc = (@crc / 256) ^ Substring(@Lookup, ((@crc & 0xFF) ^ Ascii(Substring(@input, V.Number, 1))) * 4 + 1, 4)
FROM master.dbo.spt_values V
WHERE V.type = 'P' AND V.number BETWEEN 1 AND Len(@input)
SET @crc = ~@crc;
SELECT @crc CRC32, Convert(VARBINARY(4), @crc) CRC32Hex;
Tried in sql but did not work