File: masked.py

package info (click to toggle)
python-bitarray 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,288 kB
  • sloc: python: 11,456; ansic: 7,657; makefile: 73; sh: 6
file content (17 lines) | stat: -rw-r--r-- 354 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# example to illustrate masked indexing
from bitarray import bitarray


a = bitarray('1110000')
b = bitarray('1100110')
# select bits from a where b is 1
assert a[b] == bitarray('1100')

# set bits in a where b is 1
a[b] = bitarray('1010')
assert a == bitarray('1010100')

# delete bits in a where b is 1
del a[b]
assert a == bitarray('100')
print("Ok")