如何将一个字节和4位从另一个字节转换为使用位的短字节?
使用Bitwise,我们如何以最具性能的方式将这3个字节转换为两条短裤?:
(1111111)(01111110)(10000001)3字节
(111111110111)(111010000001)2个短裤
找到了一种将两个字节组合为简短的方法,但是对于1个字节和4位组合,尝试了多种方法,但没有成功。感谢您的帮助。
byte byt1 = -1; // 11111111
byte byt2 = 126;// 01111110
byte byt3 = 129;// 10000001
short s_1_2 = (short) ((byt1 << 8) | (byt2 & 0xFF));
// value is 1111111101111110
short s1 = // want to be 111111110111
short s2 = // want to be 111010000001
Using bitwise, how could we convert these 3 bytes to two shorts in this pattern in the most performant way?:
(11111111)(01111110)(10000001) 3 bytes
(111111110111)(111010000001) 2 shorts
Found a way to combine two bytes into a short, but for a combination of 1 byte and 4 bits tried a variety of ways for hours with no success. Thanks for your help.
byte byt1 = -1; // 11111111
byte byt2 = 126;// 01111110
byte byt3 = 129;// 10000001
short s_1_2 = (short) ((byt1 << 8) | (byt2 & 0xFF));
// value is 1111111101111110
short s1 = // want to be 111111110111
short s2 = // want to be 111010000001
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能性之一是以下内容:
One of the possibilities is the following: