Skip to content

Instantly share code, notes, and snippets.

View Ardhead's full-sized avatar

Aleksandr Shevtsov Ardhead

View GitHub Profile
const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const B64_IDX = Object.fromEntries([...B64].map((c, i) => [c, i]));
const pushBits = (bits, val, len) => {
for (let i = len - 1; i >= 0; i--) bits.push((val >> i) & 1);
};
const readBits = (bits, idx, len) => {
let val = 0;
for (let i = 0; i < len; i++) val = (val << 1) | bits[idx + i];