java中的字节十六进制计算
我是字节的电枢..十六进制计算等...我的应用程序要求我通过套接字以字节的形式发送一些数据...
1st byte -> [ { ]
2nd byte -> [ { ]
3rd byte -> [ 0xD1 ]
4th byte -> [ 0x00 ]
5th byte -> [sum of first,second and third hex value]
6th byte -> [ } ]
7th byte -> [ } ]
这是一个示例 我怎样才能执行这样的操作,在每个字节中分配十六进制值,将这些字节存储在数组中。我对此有点困惑。有人可以帮助我吗???
i am an amature in byte..hex calculation etc...my application requires me to send some data through sockets in the form of bytes...
1st byte -> [ { ]
2nd byte -> [ { ]
3rd byte -> [ 0xD1 ]
4th byte -> [ 0x00 ]
5th byte -> [sum of first,second and third hex value]
6th byte -> [ } ]
7th byte -> [ } ]
This is a sample
How can i perform such an operation of assigningthe hex values in each byte, storing these bytes in an array.. I got a bit stuck up with this.. could someone help me out ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
十六进制只是字节值的表示法。使用普通的
+
将它们加在一起。Hex is just a notation for the value in the byte. Add them together using ordinary
+
.由于某种原因,人们经常将数字的表示形式与数字的值混淆。您添加的值不是十六进制、十进制或二进制。它们只是数字。一个字节就是一个字节。您只需用 + 添加两个字节即可,这没有什么神奇的。无论您将结果显示为十六进制还是十进制或任何其他形式,它的工作原理都是相同的:
示例:
People often confuse the representation of a number with the value of a number for some reason. The values you are adding are not hexadecimal or decimal or binary. They are just numbers. A byte is a byte. You can just add two bytes with + and there's nothing magical about it. It works the same whether you show the results as hex or decimal or anything:
Example:
您可以构建字节数组,例如:
you can build up array of bytes like :