1.0.3 • Published 5 years ago

padded-decimal-to-binary v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

paddedDec2Bin

This is a light-weight, no-dependency JavaScript library for converting a decimal number into binary with optional padding zeros.

Installation

npm install padded-decimal-to-binary

Usage

Import

import { paddedDec2Bin } from 'padded-decimal-to-binary';

Function call

const fiveInBinary = paddedDec2Bin(5);

console.log(fiveInBinary); // 101

Params

  • decimal (number) - required The decimal value to be converted.
  • length (number) - optional The length of the output. Ignored if the output length is actually longer than the parameter.

Examples

paddedDec2Bin(5) // 101
paddedDec2Bin(5, 2) // 101 (output length is already longer than 2)
paddedDec2Bin(5, 4) // 0101 (padded)

Test

I don't know how to write test. Learning.