Comments (1)
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:
- a slice of
a
is created. This is a newBitArray
object with a copy of the data (BitArray
is mutable so it can't be a view on the data). - This new
BitArray
gets converted to an unsigned integer. - That integer gets 'or'ed with the integer 0b0010
- The new
BitArray
's unsigned integer property is set to the new integer value. - 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)
- Stray, invalid `bitstring/plugin_test.py` in the sdist for 4.1.2 HOT 3
- Change names of fp8 types? HOT 1
- Unreasonably slow operations HOT 1
- Rationalise Error classes
- Add scale factor for interpretations HOT 1
- BitArray(random.getrandbits(128)) fails HOT 2
- Dtypes should know their return type HOT 1
- 4.1.2: test_plugin.py problems HOT 1
- Use standard range checking - throw less exceptions
- bitstring 4.1.3 no longer allows packing and reading bytes without a defined length HOT 2
- Dtype could be callable HOT 1
- Allow count to count more than just bits.
- Tighten up token length rules. HOT 1
- Opening a file using filename keyword seems to lock the file as if it's in write mode HOT 7
- Add support for LSB0 on a per object / instance basis HOT 2
- Iterating using over Bits.find() causes an infinite loop HOT 5
- Add support for NO_COLOR terminal variable
- Shortcut for current dtype in pp.
- ImportError: cannot import name 'BitString' from 'bitstring' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitstring.