NetTalk Central

Author Topic: Clarion crc32 in java script  (Read 3093 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1871
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Clarion crc32 in java script
« on: August 28, 2020, 11:23:04 AM »
Hi, I need a js crc32() function to get the same values that the one in clarion.
Ive found this, but the result is not the same as clarion.
Thanks

Code: [Select]
function makeCRCTable(){
    var c;
    var crcTable = [];
    for(var n =0; n < 256; n++){
        c = n;
        for(var k =0; k < 8; k++){
            c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
        }
        crcTable[n] = c;
    }
    return crcTable;
}

function crc32(str) {
    var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
    var crc = 0 ^ (-1);
    for (var i = 0; i < str.length; i++ ) {
        crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
    }
    return (crc ^ (-1)) >>> 0;
};
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Clarion crc32 in java script
« Reply #1 on: August 30, 2020, 10:59:26 PM »
There are quite a few CRC32 functions out there - there are lots of different starting vectors.
Alas, I do not know which one the Clarion CRC32 function uses.

Cheers
Bruce