fix crc check not being available

This commit is contained in:
Lewis Moten
2024-05-17 21:45:00 -04:00
parent bef7fcd0f3
commit 6f4b898f52
3 changed files with 35 additions and 14 deletions

View File

@@ -1,8 +1,13 @@
export const numberToBytes = (number, bitLength) => {
const byteCount = Math.ceil(bitLength/8);
const bytes = [];
for(let i = 0; i < byteCount; i++) {
bytes.push((number >> (8 * (byteCount - 1 - i))) & 0xFF);
let byte = 0;
for(let i = 0; i < bitLength; i++) {
let bit = (number >> (bitLength - 1 - i)) & 1;
byte = (byte << 1) | bit;
if((i + 1) % 8 === 0 || i === bitLength - 1) {
bytes.push(byte);
byte = 0;
}
}
return bytes;
}