gpt4 book ai didi

java - 它在位运算中代表什么?

转载 作者:行者123 更新时间:2023-11-29 06:18:31 25 4
gpt4 key购买 nike

这些代码行代表什么?

payloadType = header[1] & 127;
sequenceNumber = unsigned_int(header[3]) + 256*unsigned_int(header[2]);
timeStamp = unsigned_int(header[7])
+ unsigned_int(header[6])
+ 65536*unsigned_int(header[5])
+ 16777216*unsigned_int(header[4]);

header 是一个 byte[12],方法 unisigned_int 是这样的:

private int unsigned_int(byte b) {
if(b >= 0) {
return b;
}
else {
return 256 + b;
}
}

感谢您的回答!

最佳答案

 payloadType = header[1] & 127;

去掉 header 1 的符号位/得到底部 7 位

sequenceNumber = unsigned_int(header[3]) + 256*unsigned_int(header[2]);

从头部提取一个16位的值

 timeStamp = unsigned_int(header[7])
+ unsigned_int(header[6])
+ 65536*unsigned_int(header[5])
+ 16777216*unsigned_int(header[4]);

从 header 中提取一个 32 位值。由 Mark Byers 观察到的错误。

private int unsigned_int(byte b) {
if(b >= 0) {
return b;
}
else {
return 256 + b;
}
}

将一个从 -128 到 127 的整数(即一个字节)转换为一个表示为整数的 8 位无符号整数。相当于

 return b & 255

关于java - 它在位运算中代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4132858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com