Skip to content

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

License

Notifications You must be signed in to change notification settings

thammarith/paddedDec2Bin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published