iota-ternary
Version:
Fast utility functions for conversion between trytes, trits and bytes
20 lines (19 loc) • 581 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function tritsToBytes(trits) {
const size = Math.ceil(trits.length / 5);
const bytes = Buffer.alloc(size);
for (var i = 0; i < size; ++i) {
bytes.writeInt8(((trits[i * 5 + 0] || 0)
+
(trits[i * 5 + 1] || 0) * 3
+
(trits[i * 5 + 2] || 0) * 9
+
(trits[i * 5 + 3] || 0) * 27
+
(trits[i * 5 + 4] || 0) * 81), i);
}
return bytes;
}
exports.tritsToBytes = tritsToBytes;