UNPKG

@signumjs/util

Version:

Useful utilities and tools for building Signum Network applications

22 lines 906 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.twosComplementBinary = void 0; /** @ignore */ /** @internal */ /** */ const bignumber_js_1 = __importDefault(require("bignumber.js")); const twosComplementBinary = (bn) => { // we manually implement our own two's complement (flip bits, add one) let bin = bn.multipliedBy(-1).toString(2); while (bin.length % 8) { bin = '0' + bin; } const prefix = ('1' === bin[0] && -1 !== bin.slice(1).indexOf('1')) ? '11111111' : ''; bin = bin.split('').map(i => '0' === i ? '1' : '0').join(''); return new bignumber_js_1.default(prefix + bin, 2).plus(1); }; exports.twosComplementBinary = twosComplementBinary; //# sourceMappingURL=twosComplementBinary.js.map