In erlang, there are bitwise operations to operate on integers, for example:
1> 127 bsl 1.
254
there is also the ability to pack integers into a sequence of bytes
<< 16#7F, 16#FF >>
is it possible, or are there any operators or BIFs that can perform bitwise operations (eg AND, OR, XOR, SHL, SHR) on binary packed data?
for example (if bsl worked on binary packages - which it does not):
1> << 16#7F, 16#FF >> bsl 1.
<< 255, 254 >>
Try out this way:
bbsl(Bin,Shift) -> <<_:Shift,Rest/bits>> = Bin, <<Rest/bits,0:Shift>>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With