java - Xor starting with the significant bit -
int a= 21;//10101 int b = 269;//100001101
a^b
10101 100001101 --------- 100011000
but want do
10101 100001101 --------- 001011101
is there way without changing original numbers?
you can shift a
align b
on left. sample code below works example not handle overflows etc. should give starting point though.
int = 21; int b = 269; int shift = integer.numberofleadingzeros(a) - integer.numberofleadingzeros(b); int c = (a << shift) ^ b; system.out.println(integer.tobinarystring(c)); // 1011101
Comments
Post a Comment