Say I have a bytearray like the following :
mask = bytearray([0b0001, 0b0100, 0b0111])
,
where each bit represents a certain flag. I would like to add a flag to slices of the mask array like so :
mask[0:2] = mask[0:2] | 0b1000
but I get a TypeError :
TypeError: unsupported operand type(s) for |: 'bytearray' and 'int'
what would be the most elegant way of doing this?
Tried this, as well :
masks[0:2] = bytearray([bin(m | 0b0001) for m in masks[0:2]])
with error :
string must be of size 1
Thanks!