bitwise AND in java with operator "&" -
i read code following:
byte[] bts = {8, 0, 0, 0}; if ((bts[i] & 0x01) == 0x01)
does same thing
if (bts[i] == 0x01)
if not,what's difference between them?
and first way trying here?
no, doesn't.
if(bts[i] == 0x01)
means if bts[i] equal 1.
if((bts[i] & 0x01) == 0x01)
means if least significant bit of bts[i] equal 1.
example.
bts[i] = 9 //1001 in binary if(bts[i] == 0x01) //false if((bts[i] & 0x01) == 0x01) //true
Comments
Post a Comment