UNPKG

neo-convertor

Version:

A tool to convert neo smart contract data to human-readable one

91 lines (90 loc) 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const UintVariable_1 = require("./UintVariable"); // import { BigInteger } from '../bigInteger'; class Uint64 extends UintVariable_1.UintVariable { constructor(low = 0, high = 0) { super([low, high]); this.and = (other) => { if (typeof other === "number") { return this.and(new Uint64(other)); } var bits = new Uint32Array(this.bits.length); for (var i = 0; i < bits.length; i++) bits[i] = this.bits[i] & other.bits[i]; return new Uint64(bits[0], bits[1]); }; this.not = () => { var bits = new Uint32Array(this.bits.length); for (var i = 0; i < bits.length; i++) bits[i] = ~this.bits[i]; return new Uint64(bits[0], bits[1]); }; this.or = (other) => { if (typeof other === "number") { return this.or(new Uint64(other)); } var bits = new Uint32Array(this.bits.length); for (var i = 0; i < bits.length; i++) bits[i] = this.bits[i] | other.bits[i]; return new Uint64(bits[0], bits[1]); }; // public readonly parse = (str: string): Uint64 => { // let bi = BigInteger.parse(str); // if (bi.bitLength() > 64) { // throw new RangeError(); // } // let arr = new Uint32Array(bi.toUint8Array(true, 8).buffer); // return new Uint64(arr[0], arr[1]); // } this.rightShift = (shift) => { if (shift === 0) { return this; } let shift_units = shift >>> 5; shift = shift & 0x1f; let bits = new Uint32Array(this.bits.length); for (let i = 0; i < bits.length; i++) { if (shift === 0) { bits[i] = this.bits[i + shift_units]; } else { bits[i] = this.bits[i + shift_units] >>> shift | this.bits[i + shift_units + 1] << (32 - shift); } } return new Uint64(bits[0], bits[1]); }; this.leftShift = (shift) => { if (shift === 0) { return this; } let shift_units = shift >>> 5; shift = shift & 0x1f; let bits = new Uint32Array(this.bits.length); for (let i = 0; i < bits.length; i++) { if (shift === 0) { bits[i] = this.bits[i - shift_units]; } else { bits[i] = this.bits[i - shift_units] << shift | this.bits[i - shift_units + 1] << (32 - shift); } } return new Uint64(bits[0], bits[1]); }; this.subtract = (other) => { let low = this.bits[0] - other.bits[0]; let high = this.bits[1] - other.bits[1] - (this.bits[0] < other.bits[0] ? 1 : 0); return new Uint64(low, high); }; // public readonly toString = (): string => { // return (new BigInteger(this.bits.buffer)).toString(); // } this.toUint32 = () => { return this.bits[0]; }; } } Uint64.MaxValue = new Uint64(0xffffffff, 0xffffffff); Uint64.MinValue = new Uint64(); Uint64.Zero = new Uint64(); exports.Uint64 = Uint64;