bytearray - In Java, how do you iterate over the bits of two byte arrays? -
for 2 byte arrays , b of equal length, i'd find first unset bit in byte array set in byte array b, , return zero-based index or position of bit. how can so?
for example:
a: 1111 0000 0101 b: 1111 0000 1010 ^
try this:
int length = a.length<b.length? a.length:b.length; (int i=0; i<length; i++) { int x = a[i]^b[i]; if (x != 0) { (int j=0; true; j++) { if ((x&1) == 1) return byte.size*i+j; x >>= 1; } } } return -1;
Comments
Post a Comment