0.0.2 • Published 2 years ago

uint128 v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Installation

npm install uint128

Usage

const { Int128, UInt128 } = require('uint128');

const encodedUInt128 = UInt128.encodeBE(1000000000000000000000000000000n);
console.log(encodedUInt128, UInt128.decodeBE(encodedUInt128))

const encodedInt128 = Int128.encodeBE(-1000000000000000000000000000000n);
console.log(encodedInt128, Int128.decodeBE(encodedInt128))

Classes

Int128

encodeBE(int) ⇒ Buffer

Encodes a 128 bit integer as Big Endian Buffer.

ParamTypeDescription
intBigIntInteger to encode

decodeBE(buffer, offset = 0) ⇒ BigInt

Decodes a Big Endian Buffer into a 128 bit integer

ParamTypeDescription
bufferBufferBuffer to decode
offsetIntegerOffset to decode at

encodeLE(int) ⇒ Buffer

Encodes a 128 bit integer as Little Endian Buffer.

ParamTypeDescription
intBigIntInteger to encode

decodeLE(buffer, offset = 0) ⇒ BigInt

Decodes a Little Endian Buffer into a 128 bit integer

ParamTypeDescription
bufferBufferBuffer to decode
offsetIntegerOffset to decode at

UInt128

encodeBE(int) ⇒ Buffer

Encodes a 128 bit unsigned integer as Big Endian Buffer.

ParamTypeDescription
intBigIntInteger to encode

decodeBE(buffer, offset = 0) ⇒ BigInt

Decodes a Big Endian Buffer into a 128 bit unsigned integer

ParamTypeDescription
bufferBufferBuffer to decode
offsetIntegerOffset to decode at

encodeLE(int) ⇒ Buffer

Encodes a 128 bit unsigned integer as Little Endian Buffer.

ParamTypeDescription
intBigIntInteger to encode

decodeLE(buffer, offset = 0) ⇒ BigInt

Decodes a Little Endian Buffer into a 128 bit unsigned integer

ParamTypeDescription
bufferBufferBuffer to decode
offsetIntegerOffset to decode at