Giter VIP home page Giter VIP logo

Comments (1)

scott-griffiths avatar scott-griffiths commented on June 28, 2024

Hi, thanks for the bug report. The 4.1.2 release should be (almost) bug free, but the lsb0 code is relatively new so I wouldn't be surprised if there are still some edge cases.

The problem here though is a bit subtle, and it wasn't obvious to me, but I don't think it's a bug.

If you look at the line a[0:4].u |= 0b0010 what's happening is:

  1. a slice of a is created. This is a new BitArray object with a copy of the data (BitArray is mutable so it can't be a view on the data).
  2. This new BitArray gets converted to an unsigned integer.
  3. That integer gets 'or'ed with the integer 0b0010
  4. The new BitArray's unsigned integer property is set to the new integer value.
  5. The new BitArray is thrown away as it's not referred to again!

To look at it another way, because of the conversion to an integer the |= operator is acting on that integer, rather than the slice of a.

The line is equivalent to this line, which doesn't change the value of a:

>>> a[0:4].u = a[0:4].u | 0b0010

whereas what I think you need is this line, which does change a (and does work).

>>> a[0:4] = a[0:4].u | 0b0010

Incidentally, another way of doing this would be just a[0:4] |= '0b0010'

Hopefully that makes sense?

from bitstring.

Related Issues (20)

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.