csBigInteger.js: C# BigInteger implementation on javascript
npm install csbigintegerThis is csBigInteger.js project, a C# BigInteger implementation on JavaScript.
The idea is to provide full compatibility with C# Numerics implementation, regarding hexstring format and little-endness.
Some auxiliar functions are also provided, regarding Fixed8 format.
Since version 3.0, it is using bn.js library (https://github.com/indutny/bn.js) to handle big internals.
js
// get library as 'csbiginteger', e.g., CommonJS: "let csbiginteger = require('csbiginteger')"
var x1 = new csbiginteger.csBigInteger("0xff", 16); // -1 in csBigInteger
var bx1 = x1.asBN(); // get BN.js internals
var x2 = new csbiginteger.csBigInteger(5);
var bx2 = x2.asBN(); // get BN.js internals
var bx3 = bx2.add(bx1); // performs '-1' + '5'
bx3.toString(10); // outputs '4'
`$3
Classic JS:
`html
`If you want as ES6 module:
`html
``js
csBigInteger = csbiginteger.csBigInteger;
csFixed8 = csbiginteger.csFixed8;
x = new csBigInteger(1000);
y = new csFixed8(1000);
`$3
npm install csbiginteger`js
const csBigInteger = require('csbiginteger').csBigInteger;
var x = new csBigInteger(255);
x.toHexString();
// "ff00"
var y = x + 1;
// 256 (JS unsafe number)
const BN = require('bn.js');
var z = x.asBN().add(new BN(1));
z.toString(10);
// "256" (BN safe number)
`For Developers
$3
npm test$3
npm run build$3
npm version minor$3
git push origin master --tagsnpm publish`
Main maintainer is @igormcoelho. Thanks a lot to @snowypowers for the good advices and @ixje on endianess discussions.
MIT License
Copyleft 2018