
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
convert-binary
Advanced tools
An NPM package to convert various data types to and from binary representation
An NPM package to convert various data types to and from binary representation. Easily convert numbers, strings, hex, octal, and more to and from binary format.
✅ Convert numbers, strings, hex, and more to binary
✅ Convert binary back to readable formats
✅ Supports floats, booleans, and bitwise operations
✅ No dependencies – lightweight and fast!
Install the package via npm:
npm install convert-binary
const convert = require('convert-binary');
import convert from 'convert-binary';
Convert a number to binary
const { toBinaryFromNumber } = require('convert-binary');
console.log(toBinaryFromNumber(10));
// Output: '1010'
Convert a string to binary
const { toBinaryFromString } = require('convert-binary');
console.log(toBinaryFromString("Hello"));
// Output: '0100100001100101011011000110110001101111'
Convert binary to a number
const { binaryToNumber } = require('convert-binary');
console.log(binaryToNumber("1010"));
// Output: 10
Convert binary to a string
const { binaryToString } = require('convert-binary');
console.log(binaryToString("0100100001100101011011000110110001101111"));
// Output: 'Hello'
| Function | Description | Example Input | Example Output |
|---|---|---|---|
| toBinaryFromNumber(num) | Converts a number to binary. | 10 | "1010" |
| toBinaryFromString(str, encoding="utf-8") | Converts a string to binary. | "A" | "01000001" |
| toBinaryFromHex(hexStr) | Converts a hex string to binary. | "A" | "1010" |
| toBinaryFromOctal(octalStr) | Converts an octal string to binary. | "12" | "1010" |
| toBinaryFromBoolean(bool) | Converts a boolean to binary. | true | "1" |
| toBinaryFromFloat(floatNum) | Converts a floating point number to binary. | 5.75 | "01000000101110000000000000000000" |
| Function | Description | Example Input | Example Output |
|---|---|---|---|
| binaryToNumber(binStr) | Converts a binary string to a number. | "1010" | 10 |
| binaryToString(binStr, encoding="utf-8") | Converts binary to a string. | "01000001" | "A" |
| binaryToHex(binStr) | Converts binary to hex. | "1010" | "A" |
| binaryToOctal(binStr) | Converts binary to octal. | "1010" | "12" |
| binaryToBoolean(binStr) | Converts binary to a boolean. | "1" | true |
| binaryToFloat(binStr) | Converts binary to a float. | "01000000101110000000000000000000" | 5.75 |
| Function | Description | Example Input | Example Output |
|---|---|---|---|
| padBinary(binStr, length) | Pads a binary string with leading zeros. | "101", 8 | "00000101" |
| chunkBinary(binStr, chunkSize) | Splits a binary string into chunks. | "11001100", 4 | ["1100", "1100"] |
| invertBinary(binStr) | Inverts (flips) binary bits. | "1010" | "0101" |
| xorBinary(bin1, bin2) | Performs XOR operation on two binary strings. | "1100", "1010" | "0110" |
| andBinary(bin1, bin2) | Performs AND operation on two binary strings. | "1100", "1010" | "1000" |
| orBinary(bin1, bin2) | Performs OR operation on two binary strings. | "1100", "1010" | "1110" |
| notBinary(binStr) | Performs NOT operation (bit inversion). | "1010" | "0101" |
| shiftBinaryLeft(binStr, places) | Shifts a binary string left by n places. | "1010", 2 | "101000" |
| shiftBinaryRight(binStr, places) | Shifts a binary string right by n places. | "1010", 2 | "10" |
Want to improve convert-binary? Follow these steps:
FAQs
An NPM package to convert various data types to and from binary representation
The npm package convert-binary receives a total of 3 weekly downloads. As such, convert-binary popularity was classified as not popular.
We found that convert-binary demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.