Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bn

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bn

JS Bigint import

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93K
decreased by-19.87%
Maintainers
1
Weekly downloads
 
Created

What is bn?

The 'bn' npm package is a library for arbitrary-precision arithmetic in JavaScript. It is primarily used for handling large integers and performing mathematical operations on them, which are beyond the safe integer range of JavaScript's native number type.

What are bn's main functionalities?

Arbitrary-Precision Arithmetic

This feature allows you to perform arithmetic operations on large integers that exceed JavaScript's native number limits. The code sample demonstrates creating two large numbers and adding them together using the 'bn' package.

const BN = require('bn.js');
const a = new BN('123456789012345678901234567890');
const b = new BN('987654321098765432109876543210');
const sum = a.add(b);
console.log(sum.toString()); // '1111111110111111111011111111100'

Modular Arithmetic

This feature allows you to perform modular arithmetic operations, which are useful in cryptography and number theory. The code sample shows how to compute the modulus of two large numbers.

const BN = require('bn.js');
const a = new BN('123456789012345678901234567890');
const b = new BN('987654321098765432109876543210');
const mod = a.mod(b);
console.log(mod.toString()); // '123456789012345678901234567890'

Bitwise Operations

The 'bn' package supports bitwise operations on large integers. The code sample demonstrates a left bitwise shift operation on a large number.

const BN = require('bn.js');
const a = new BN('123456789012345678901234567890');
const shifted = a.ushln(2);
console.log(shifted.toString()); // '493827156049382715604938271560'

Other packages similar to bn

FAQs

Package last updated on 13 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc