如何在java或c中从8位样本中生成1个字节?
我有带有随机值(称为标头)的 8 位样本,并且有带有十六进制值的命令,请参见下文:
[8 bit][command]
\ |
\ \------------------ [01 30 00 00 = hex start the machine]
\
+-------------------+
| 00001111 = hi |
| 00000000 = hello |
| 00000101 = wassup |
+-------------------+
如何将 8 位样本转换为 1 字节并将其与上面的十六进制值连接?
I have 8 bit samples with random values (called headers) and I have commands with hexadecimal values, see bellow:
[8 bit][command]
\ |
\ \------------------ [01 30 00 00 = hex start the machine]
\
+-------------------+
| 00001111 = hi |
| 00000000 = hello |
| 00000101 = wassup |
+-------------------+
How do you translate the 8 bit samples to 1 byte and join it with the above hex value ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这两种语言中,您都可以使用按位运算。
因此,在 C 中,如果您有:
您可以将它们连接成 64 位数据类型,如下所示:
如果您想要一个输出字节数组(用于通过 RS-232 或其他方式进行序列化),那么您可以执行以下操作:
In both languages, you can use bitwise operations.
So in C, if you have:
You can concatenate these into e.g. a 64-bit data type as follows:
If you instead want an array of output bytes (for serializing over RS-232 or whatever), then you can do something like: