Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ofarukcaki/int-to-binary
Integer to signed/unsigned binary converter with given bit length.
https://github.com/ofarukcaki/int-to-binary
Last synced: about 1 month ago
JSON representation
Integer to signed/unsigned binary converter with given bit length.
- Host: GitHub
- URL: https://github.com/ofarukcaki/int-to-binary
- Owner: ofarukcaki
- License: mit
- Created: 2019-11-20T09:32:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T09:36:07.000Z (about 5 years ago)
- Last Synced: 2024-11-14T05:14:03.638Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# int-to-binary
*Integer to signed/unsigned binary converter.*
## Install**npm**:
`npm i int-to-binary`or **yarn**:
`yarn add int-to-binary`## Usage
Include the module
```javascript
const itb = require("int-to-binary");//convet number to signed (length) bits binary
itb.signed(number, length);//convet number to unsigned (length) bits binary
itb.unsigned(number, length);
```## Examples
### Integer to unsigned binary:
```javascript
const itb = require("int-to-binary");console.log(itb.unsigned(7, 4));
// 0111console.log(itb.unsigned(7, 5));
// 00111console.log(itb.unsigned(32, 6));
// 100000console.log(itb.unsigned(1));
// 00000000000000000000000000000001
// default length is 32 bits if not provided
```### Integer to signed binary:
```javascript
const itb = require("int-to-binary");console.log(itb.signed(-1, 4));
// 1111console.log(itb.signed(-1, 5));
// 11111console.log(itb.signed(32, 6));
// 011111console.log(itb.signed(-1));
// 11111111111111111111111111111111
// default length is 32 bits if not provided
```