This 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.
// get library as 'csbiginteger', e.g., CommonJS: "let csbiginteger = require('csbiginteger')"varx1=newcsbiginteger.csBigInteger("0xff",16);// -1 in csBigIntegervarbx1=x1.asBN();// get BN.js internalsvarx2=newcsbiginteger.csBigInteger(5);varbx2=x2.asBN();// get BN.js internalsvarbx3=bx2.add(bx1);// performs '-1' + '5'bx3.toString(10);// outputs '4'Classic JS:
<scriptsrc="https://unpkg.com/csbiginteger/dist/csbiginteger"></script>If you want as ES6 module (remember to put .mjs extension):
<scripttype="module">importcsbigintegerfrom"https://unpkg.com/csbiginteger/dist/csbiginteger-es6.mjs";</script>csBigInteger=csbiginteger.csBigInteger;csFixed8=csbiginteger.csFixed8;x=newcsBigInteger(1000);y=newcsFixed8(1000);npm install csbiginteger
constcsBigInteger=require('csbiginteger').csBigInteger;varx=newcsBigInteger(255);x.toHexString();// "ff00"vary=x+1;// 256 (JS unsafe number)constBN=require('bn.js');varz=x.asBN().add(newBN(1));z.toString(10);// "256" (BN safe number)npm test
npm run build
npm version minor
git push origin master --tags
npm publish
Main maintainer is @igormcoelho. Thanks a lot to @snowypowers for the good advices and @ixje on endianess discussions.
MIT License
Copyleft 2018