Coder Social home page Coder Social logo

Comments (4)

feross avatar feross commented on July 30, 2024

The whole point of this package is to compactly store bits in a larger buffer. It's expected that when you view the buffer as a bunch of 32 bit ints it will look like nonsense.

I don't know what to tell you.

from bitfield.

feross avatar feross commented on July 30, 2024

If you want to get a friendly array, loop over the BitField using b.get(i) to extract the values and put them into an array yourself.

from bitfield.

ad34 avatar ad34 commented on July 30, 2024

got it , but why when you call b.set(0) , it internally set the most significant bit ?
why not using (1 << (i % 8)) instead? if you make this the buffer will look like this

[1, 0, 0, 0, 0, 0, 0, 0, …]

if you b.set(1) you can

[3, 0, 0, 0, 0, 0, 0, 0, …]

with your module you get

[128, 0, 0, 0, 0, 0, 0, 0, …]
and
[64, 0, 0, 0, 0, 0, 0, 0, …]

if anyone has the same kind of issue to export as 32 bits integers , you can use swap32() on the buffer

from bitfield.

feross avatar feross commented on July 30, 2024

It sets bits from left to right, because that's the most useful for building up a bitfield when working with low-level wire protocols.

from bitfield.

Related Issues (9)

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.