[問題] 請問一下為何要做bitwise運算
最近在研究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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):