int64-node
int64-node is a JavaScript library that provides support for handling 64-bit integer numbers in Node.js. JavaScript's native Numbers are represented as IEEE 754 double-precision floats, which limits the range of values that can be accurately represented to ±2^53
. For projects requiring precise 64-bit integer handling, such as node-thrift, int64-node
comes to the rescue.
Table of Contents
Installation
You can install int64-node via npm:
npm install int64-node
Usage
Creating Int64 Instances
const Int64 = require('int64-node');
const int1 = new Int64(0x12345678, 0x9abcdef0);
const int2 = new Int64('123456789abcdef0');
Performing Arithmetic Operations
const result1 = int1 + 1;
const result2 = int2 + 1;
Converting to Different Representations
const octetString1 = int1.toOctetString();
const octetString2 = int2.toOctetString();
const binaryString1 = int1.toString(2);
const binaryString2 = int2.toString(2);
Checking Integer Precision
const isInt1Finite = isFinite(int1);
const isInt2Finite = isFinite(int2);
Copying to a Buffer
const buffer1 = int1.toBuffer();
const buffer2 = new Buffer(16);
int2.copy(buffer2, 0);
Creating Int64 Instances from a Buffer
const intFromBuffer = new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]));
const intFromOffset = new Int64(new Buffer([0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4);
License
int64-node is licensed under the MIT License. See LICENSE for details.
Contributing
Interested in contributing? Please read our Contributing Guidelines for more information.
Learning
Explore our Learning Resources to get started with int64-node.
Code of Conduct
Please follow our Code of Conduct to ensure a welcoming and inclusive community.
Developer Details
Happy Coding 🚀