与硬件设备通讯,经常遇到如何获取某个字节的值,以前老是忘记,今天挤出点时间记录下来
int n;
低4位:
n & 0x01
n & 0x02
n & 0x04
n & 0x08
高4位 :
n & 0x10
n & 0x20
n & 0x40
n & 0x80
设置不同位所代表的含义:
StringBuffer buffer = new StringBuffer();
int n= n & 0xFF;
if ((n & 0x01) == 0x01) {
buffer.append()
}
if ((n & 0x02) == 0x04) {
buffer.append()
}
if ((n & 0x04) == 0x04) {
buffer.append()
}
if ((n & 0x08) == 0x08) {
buffer.append()
}
if ((n & 0x10) == 0x10) {
buffer.append()
}
if ((n & 0x20) == 0x20) {
buffer.append()
}
if ((n & 0x40) == 0x40) {
buffer.append()
}
if ((n & 0x80) == 0x80) {
buffer.append()
}