Answer the question
In order to leave comments, you need to log in
How to swap bytes?
This self-made function calculates CRC-CCITT (Kermit) and everything would be fine, but it returns
FB56 instead of 56FB... what is the best way to swap bytes?
function crc16(data) {
var crc = 0;
for (var i = 0; i < data.length; i++) {
crc ^= data.charCodeAt(i);
for (var j = 0; j < 8; j++) {
if (crc & 1) crc = 0x8408 ^ crc >>> 1;
else crc >>>= 1;
}
}
return crc;
}
console.log(crc16("test").toString(16));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question