Java字节数组操作
我试图选择字节数组中最后一个字节的低 4 位。这就是我以前在 PHP 中完成的方法,但我是 Java 新手。
$lower4bit = substr($bytes[19], -1);
//Convert the hex to decimal to get the offset value
$offset = hexdec($lower4bit);
//Select the value of the 4 bytes starting at the offset
$joinedArray = implode(array_slice($bytes, $offset, 4));
谁能指出我使用 Java 的正确方向?
I am trying to select the lower 4 bits of the last byte in a byte array. This is how I have previously done it in PHP but I am new to Java.
$lower4bit = substr($bytes[19], -1);
//Convert the hex to decimal to get the offset value
$offset = hexdec($lower4bit);
//Select the value of the 4 bytes starting at the offset
$joinedArray = implode(array_slice($bytes, $offset, 4));
Can anyone point me in the correct direction with Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样访问数组:
您可以像这样找到数组的长度:
您可以像这样隔离整数的最后 4 位:
这些应该足以构造您需要的代码。
You access an array like so:
You find the length of an array like so:
You can isolate the last 4 bits of an integer like so:
These should be sufficient to construct the code that you need.