作者Schatze (吃哈吱)
看板java
标题[问题] 请问一下为何要做bitwise运算
时间Mon Mar 28 14:56:01 2011
最近在研究android nfc的功能.
有一段是在parse出nfcrecord的payload.
请问这部份使用bitwise用意为何呢?
谢谢.
static NDEFRecord readRecord(byte[] bytes, int offset) {
int header = bytes[offset] & 0xFF;
// Does header match what we support in the bits we care about?
// XOR figures out where we differ, and if any of those are in the mask, fail
if (((header ^ SUPPORTED_HEADER) & SUPPORTED_HEADER_MASK) != 0) {
return null;
}
int typeLength = bytes[offset + 1] & 0xFF;
int payloadLength = bytes[offset + 2] & 0xFF;
String type = AbstractNDEFParsedResult.bytesToString(bytes, offset + 3, typeLength, "US-ASCII");
byte[] payload = new byte[payloadLength];
System.arraycopy(bytes, offset + 3 + typeLength, payload, 0, payloadLength);
return new NDEFRecord(header, type, payload, 3 + typeLength + payloadLength);
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.110.117.10