You are mistaken "hexadecimal digits" for "characters":
int crc = 0xFFFF;
Only 2 bytes ( 0xFF only 1 byte). For an ANSI 4-character CRC, you need 4 bytes ( 0xFFFFFFFF ).
You will have to adapt the rest of the code for working with a double leg, comment if you do not know how to do this.
PS: you can do this with less than 4 bytes, but it will complicate everything that is needed.
walen source share