JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
applying xor to decimal number | Reply
Hi
in SRM 491 250 : OneDigitDifference
I tried to use xor to state that 2 numbers differ by one digit
like :
1907654321 , 907654321
but didnt work
I want somehow to to use xor to get one digit only when the above case


Thanks
Re: applying xor to decimal number (response to post by mshawki86) | Reply
You can only use the normal xor function with binary numbers, but you can do something like the following
int dif(int a, int b) // returns the number of different places
{
 
   int num = 0;
 
   while(a>0 || b>0)
   {
      if(((a%10)^(b%10))!=0)
      {
         num++;
      }
       a/=10;
       b/=10;
   }
 
   return num;
}
RSS