Socket
Socket
Sign inDemoInstall

base-conversion-kit

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    base-conversion-kit

Perform operations with numbers in different bases


Version published
Weekly downloads
8
decreased by-38.46%
Maintainers
1
Install size
9.54 kB
Created
Weekly downloads
 

Readme

Source

Base Conversion Kit

Say Thanks!

The Base Conversion Kit is a JavaScript package designed to simplify number operations across different bases. Whether you're working with binary, octal, decimal, or hexadecimal numbers, this package provides convenient functions for conversions and basic arithmetic operations.

Installation

You can install the Base Conversion Kit using npm:

npm install base-conversion-kit

Usage

Converting Numbers

The package offers a flexible function for converting numbers from any base to another:

const { convertToBaseN, convertBase } = require('base-conversion-kit');

// Convert a decimal number to binary
const binaryResult = convertToBaseN(42, 2);
console.log(`Binary representation: ${binaryResult}`);

// Convert a hexadecimal number to octal
const octalResult = convertBase("1A", 8, 16);
console.log(`Octal representation: ${octalResult}`);

Performing Arithmetic Operations

Performing arithmetic operations on numbers from different bases is seamless:

const { multiplyNumbers, addNumbers, subtractNumbers } = require('base-conversion-kit');

// Multiply two binary numbers
const resultBinary = multiplyNumbers("101", "110", 2);
console.log(`Binary multiplication result: ${resultBinary}`);

// Add two decimal numbers
const resultAddition = addNumbers("15", "7", 10);
console.log(`Decimal addition result: ${resultAddition}`);

// Subtract two hexadecimal numbers
const resultSubtraction = subtractNumbers("1A", "B", 16);
console.log(`Hexadecimal subtraction result: ${resultSubtraction}`);

Examples

Example 1: Adding Binary Numbers

const { addNumbers } = require('base-conversion-kit');

const result = addNumbers("101", "110", 2);
console.log(`Binary addition result: ${result}`);

Example 2: Converting and Adding

const { convertToBaseN, addNumbers } = require('base-conversion-kit');

// Convert decimal numbers to binary and add
const binarySum = addNumbers(
    convertToBaseN(10, 2),
    convertToBaseN(5, 2),
    2
);
console.log(`Binary sum: ${binarySum}`);

Contributing

Feel free to contribute to the development of the Base Conversion Kit. If you encounter issues, have suggestions, or want to add features, please submit a pull request or open an issue on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Last updated on 20 Nov 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc