Skip to content

sweetim/bit-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bit converter

Build Status codecov.io devDependency Status

This module is inspired by C# BitConverter class to convert byte array to byte, short and int.

The conversion to signed number is based on double complement.

This module is used often for serialport development which requires a lot of byte array manipulation

Example

'use strict';

const BitConverter = require('bit-converter');

const a = BitConverter.toShort([0xFF, 0xFF]);

console.log(a) // -1

//Starting index for the array = 1
const b = BitConverter.toShort([0, 0xFF, 0xFF], 1);

console.log(b) // -1

API

toByte(array[, startIndex])
toShort(array[, startIndex])
toInt(array[, startIndex])

array the source array to be converted

startIndex is the start index of the array, default is 0

About

Bit converter for nodejs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published