C 中的按位移位
我最近决定开展一个短信项目,通过手机发送和接收短信。
数据以 PDU 格式发送 - 我需要将 ASCII 字符更改为 7 位 GSM 字母字符。为此,我遇到了几个示例,例如 http://www.dreamfabric.com /sms/hello.html
此示例显示第二个七字节的最右边位,插入到第一个七字节中,以创建一个八字节。
按位移位不会导致这种情况发生,因为>>将插入到左侧,并且 <<向右。据我了解,我需要某种按位旋转来创建这个 - 谁能告诉我如何从右侧移动位并将它们插入左侧?
谢谢,
I've recently decided to undertake an SMS project for sending and receiving SMS though a mobile.
The data is sent in PDU format - I am required to change ASCII characters to 7 bit GSM alphabet characters. To do this I've come across several examples, such as http://www.dreamfabric.com/sms/hello.html
This example shows Rightmost bits of the second septet, being inserted into the first septect, to create an octect.
Bitwise shifts do not cause this to happen, as >> will insert to the left, and << to the right. As I understand it, I need some kind of bitwise rotate to create this - can anyone tell me how to move bits from the right handside and insert them on the left?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个快速算法可以做到这一点:
它将 7 位压缩缓冲区转换为 C 中的常规 ASCII 字符数组。
Here is a quick algorithm to do that:
It will convert 7bit compressed buffers to regular ASCII char arrays in C.
C 中有一些间接的方法,但我只是这样做:
这会将位向左旋转(而不是移位!)(一步)。
“ror”将向右旋转。
There are indirect ways in C but I'd simply do it like this:
This will rotate (not shift!) the bits to the left (one step).
"ror" will rotate to the right.