int64_t
64bit integer in pure Javascript
Usage
Int64
is the class which is a 64bit signed interger.
UInt64
is the class which is a 64bit unsigned interger.
const Int64 UInt64 = ;let i = 0x12345678 0x9abcdef0;console; // 1311768467463790320
Constructor
Int64 & UInt64
- new Int64(buffer)
let i = Buffer;
- new Int64(high, low)
let i = 0x12345678 0x9abcdef0;
⚠️ negative number is unacceptable
- new Int64(int)
let i = 0x123456789
⚠️ up to 2^53 - 1
Feature
Four arithmetic operations
- add(int64) (+)
let i1 = 0x12345678 0x9abcdef0;let i2 = 0x11111111 0x11111111;console; // 0x23456789abcdf001
- sub(int64) (-)
let i1 = 0x12345678 0x9abcdef0;let i2 = 0x11111111 0x11111111;console; // 0x123456789abcddf
- mul(int64) (*)
let i1 = 0xf 0x1234567678;let i2 = 0x0 0xf;console; // 0xe211111108
- div(int64) (/)
let i1 = 0x12345678 0x9abcdef0;let i2 = 0x0 0xf;console; // 0x136b06e70b74210
- mod(int64) (%)
let i1 = 0x12345678 0x9abcdef0;let i2 = 0x0 0xe;console; // 0xc
Bit operations
- and(int64) (&)
let i = 0x12345678 0x9abcdef0;console; // 0x020406080a0c0e00
- or(int64) (|)
let i = 0x12345678 0x9abcdef0;console; // 0x1f3f5f7f9fbfdfff
- xor(int64) (^)
let i = 0x12345678 0x9abcdef0;console; // 0xedcba9876543210f
- shiftRight(number, logical) (>>, >>>)
let i = 0x89abcdef 0x01234567;console; // -0x3b2a19087f6e5d4dconsole; // 0x44d5e6f78091a2b3
- shiftLeft(number) (<<)
let i = 0x12345678 0x9abcdef0;console; // 0x2468acf13579bde0
Other operation
- equal(i)
let i = 0x12345678 0x9abcdef0;console; // bool: trueconsole; // bool: falseconsole; // bool: falseconsole; // bool: false
- compare(i)
let i = 0x12345678 0x9abcdef0;console; // 1console; // -1console; // 0
Transform
- toString(radix, prefix) default radix is 10 default prefix is false
let i = 0x12345678 0x9abcdef0;console; //console; // 123456789abcdef0console
- toBuffer()
let i = 0x12345678 0x9abcdef0;console; // <Buffer 12 34 56 78 9a bc de f0>
- toUnsigned(), toSigned()
let i = 0x12345678 0x9abcdef0;let ui = i;console; // UInt64 { buffer: <Buffer 12 34 56 78 9a bc de f0> }console; // Int64 { buffer: <Buffer 12 34 56 78 9a bc de f0> }
- toNegative() (only Int64)
let i = 0x12345678 0x9abcdef0;console; // Int64 { buffer: <Buffer ed cb a9 87 65 43 21 10> }
- isNegative() (only Int64)
let i = 0x890abcde 0xf1234567console; // bool: true