62,614
社区成员
发帖
与我相关
我的任务
分享
private int getRecvCounter() {
return ((ctrlbyte3 >> 1 & 0x7f) + (ctrlbyte4 << 7 & 0x7f80));
}
public class Test1 {
byte ctrlbyte3;
byte ctrlbyte4;
public static void main(String[] args) {
Test1 t = new Test1();
t.setRecvCounter(0x7fff);
System.out.printf("%x\n", t.ctrlbyte3);
System.out.printf("%x\n", t.ctrlbyte4);
System.out.printf("%x\n", t.getRecvCounter());
}
private int getRecvCounter() {
return ((ctrlbyte3 >> 1 & 0x7f) + (ctrlbyte4 & 0xff << 7));
}
private void setRecvCounter(int recvcounter) {
ctrlbyte3 = (byte) (recvcounter << 1);
ctrlbyte4 = (byte) (recvcounter >> 7);
}
}
private int getRecvCounter() {
return ((((int) ctrlbyte3) & 0xff) >> 1) + ((((int) ctrlbyte4) & 0xff) << 7);
}
class Test2
{
byte ctrlbyte3;
byte ctrlbyte4;
public static void main(String[] args)
{
int counter=0x3773;
Test2 a=new Test2();
a.setRecvCounter(counter);
System.out.println("counter = "+counter);
System.out.println("a.getRecvCounter() = "+a.getRecvCounter());
}
private int getRecvCounter()
{
return (ctrlbyte3 << 8) + ((ctrlbyte4)&0xff); //
}
private void setRecvCounter(int recvcounter)
{
ctrlbyte3 = (byte) ((recvcounter >> 8) & 0xff); //保存高8位.
ctrlbyte4 = (byte) ((recvcounter) & 0xff); //保存低8位.
}
}