Code Monkey home page Code Monkey logo

csbiginteger-js's Introduction

csBigInteger.js

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.

How to use it

Example

// 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'

Install on web browser

Classic JS:

<script src="https://unpkg.com/csbiginteger/dist/csbiginteger"></script>

If you want as ES6 module (remember to put .mjs extension):

<script type="module">
import csbiginteger from "https://unpkg.com/csbiginteger/dist/csbiginteger-es6.mjs";
</script>
csBigInteger = csbiginteger.csBigInteger;
csFixed8 = csbiginteger.csFixed8;
x = new csBigInteger(1000);
y = new csFixed8(1000);

Install on npm

npm install csbiginteger

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

Tests

npm test

Build Webpack

npm run build

New minor version

npm version minor

Push and Publish

git push origin master --tags

npm publish

Final remarks

Main maintainer is @igormcoelho. Thanks a lot to @snowypowers for the good advices and @ixje on endianess discussions.

MIT License

Copyleft 2018

csbiginteger-js's People

Contributors

dependabot[bot] avatar igormcoelho avatar vncoelho avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

csbiginteger-js's Issues

Accept Uint8Array as input

Accept Uint8Array as input may be as good as a general list.

Same for .toByteArray (could be .toUInt8Array()).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.