Skip to content

Commit

Permalink
feat: padded bits
Browse files Browse the repository at this point in the history
  • Loading branch information
heypoom committed Dec 18, 2023
1 parent cda7710 commit 95941c9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions canvas/src/blocks/value-view/utils/bits-to-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
export const bitsToList = (nums: number[]): boolean[][] =>
nums.map((n) => {
// console.log(`n -> ${n.toString(2)}`)
const value = n.toString(2).split("").map(Number).map(Boolean)

return n.toString(2).padEnd(8, "0").split("").map(Number).map(Boolean)
if (value.length < 16) {
const pad = Math.ceil(value.length / 8) * 8
const needed = pad - value.length

if (needed > 0) {
for (let i = 0; i < needed; i++) value.push(false)
}
}

return value
})

0 comments on commit 95941c9

Please sign in to comment.