Code Monkey home page Code Monkey logo

node-bitview's Introduction

Node BitView

NodeJS Buffer interface provides a way to manipulate bytes, but what if we needed to manipulate bits?

This library was created to address the gap of a built-in bit interface.

Build Status bitHound Dependencies bitHound Overall Score issues stars license

Installation

npm install bitview --save

Initializing a view

new BitView(Length)
new BitView(buffer)
new BitView(buffer, byteOffset, length);
Buffer.from(arg)
Parameters:
length: length in bits
buffer: use an existing buffer
arg: Another interface to create a new BitView instance
arg could be an array of bits [1,0,1] or a string '1010' or a buffer.
byteOffset: default 0, starting offset of the bitview.

Methods

.flip(pos)

flips the value of the bit at location pos

.get(pos)

Returns the value of the bit at location pos  (0 or 1)

.set(pos,v)

Sets the value of a bit at location pos to v

.toString()

  Returns a string representation of the BitView.

.toBuffer()

Returns the buffer used by the view.

Properties

.length

Returns length in bits.

Usage:

const BitView = require("bitview")

const view= new BitView(10);

view.set(0,true);
console.log(view.get(0)); // true
view.flip(0)
console.log(view.get(0)); // false

const view2=BitView.from('101010');
console.log(view2.get(2)); // true

const view3=BitView.from([1, 0, 1]);
console.log(view3.get(1)); // false
console.log(view3.get(2)); // true

Implementation

BitView uses bitwise operations to manipulate each bit in a buffer (Low Complexity)

node-bitview's People

Contributors

jodevsa avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.