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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -