Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shift operations #117

Merged
merged 25 commits into from
Apr 3, 2021
Merged

Add shift operations #117

merged 25 commits into from
Apr 3, 2021

Conversation

ilanschnell
Copy link
Owner

@ilanschnell ilanschnell commented Apr 2, 2021

Add shift operations <<, >>, <<=, >>=. This PR replaces #106.

Here is an example:

>>> from bitarray import bitarray
>>> a = bitarray('0010011')
>>> a << 3
bitarray('0011000')
>>> a >>= 4
>>> a
bitarray('0000001')

Notes:

  • the length of the bitarray is unchanged by any shift operation
  • negative shifts result in ValueError: negative shift count
  • shifts larger or equal to the length of the bitarray result in a bitarray with all values 0

@ilanschnell
Copy link
Owner Author

ilanschnell commented Apr 2, 2021

I've added some notes to the initial comment above. In particular about negative shifts and shifts larger than the bitarray length, which result in (at least in C) undefined behavior, meaning not specified by the C language, but compiler/machine specific. I will wait for feedback for a day or two and then go ahead and merge.

@wmayner
Copy link

wmayner commented Apr 3, 2021

Great! Thanks for adding this :) The semantics look very clean.

@ilanschnell ilanschnell merged commit f32532e into master Apr 3, 2021
@ilanschnell ilanschnell deleted the shift branch April 4, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants