Fetch binary chunk and draw on canvas

This commit is contained in:
Guntis Smaukstelis
2025-02-03 23:33:28 +02:00
parent c1b1226678
commit df8d16ed4a
18 changed files with 898 additions and 6 deletions
+19
View File
@@ -0,0 +1,19 @@
export type U8bits = [boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean]
export function u8ToBits(dec: number): U8bits {
const str = (dec >>> 0).toString(2)
const str8 = leftPad(str)
const arr: U8bits = [false, false, false, false, false, false, false, false]
for (let i=0; i<8; i++) {
arr[i] = str8[i] === '1' ? true : false
}
return arr
}
function leftPad(str: string): string {
const padCount = 8 - str.length
for(let i=0; i<padCount; i++) {
str = '0' + str
}
return str
}