二进制格式,有位操作?例如。 << 16#7楼,16#FF>> BSL 1 [英] binary format, bitwise operations exist? eg. <<16#7F, 16#FF>> bsl 1

查看:171
本文介绍了二进制格式,有位操作?例如。 << 16#7楼,16#FF>> BSL 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Erlang中,有位操作对整数操作,例如:

  1 GT 127 BSL 1。
254

也有打包成整数的字节序列

的能力

 &LT和LT 16#7楼,16#FF&GT和GT  

有可能,还是有可以执行位运算的运算符或内建函数(如AND,OR,XOR,SHL,SHR)二进制数据打包?

例如(如果BSL的二进制包的工作 - 它不会):

  1 GT&LT和LT 16#7楼,16#FF&GT跑车和GT BSL 1。
&LT和LT 255,254 GT和GT


解决方案

试用这种方式:

  BBSL(彬,移位) -  GT; << _:Shift键,REST /位>> =斌<< REST /位,0:移位>&GT ;.

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>>.

这篇关于二进制格式,有位操作?例如。 &LT;&LT; 16#7楼,16#FF&GT;&GT; BSL 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆