• + 0 comments

    Can anyone help me what is wrong with below code? For this particular problem, there could be multiple solutions. void aOrB(int k, char* a, char* b, char* c) { long long num_a, num_b, num_c; //printf("sizeof num_a = %d \n",sizeof(num_a)); num_a = my_atoi(a); num_b = my_atoi(b); num_c = my_atoi(c); /printf("a:%s -->%ld ",a,num_a); printf("b:%s -->0x%x ",b,num_b); printf("c:%s -->0x%x \n",c,num_c);/

    // First clear the bits from value a
    num_a &= num_c;
    
    
    // Clear the bits from value b
    num_b &= num_c;
    
    
    // Now first OR a and b, then find how many bits 
    // temp is short off and it's bit position.
    long long temp = num_a | num_b;
    
    temp ^= num_c;
    
    num_a |= temp;
    
    
    if ((num_a | num_b) == num_c) 
        printf("num_a: 0x%x | num_b:0x%x = 0x%x\n",num_a, num_b, num_c);
    
    int count = (countOne(my_atoi(a)^num_a)) + (countOne(my_atoi(b)^num_b));
    
    if ( count > k)
        printf("-1");
    else {
        printf("%ld \n",num_a);
        printf("%ld \n",num_b);
    }
    
    printf("\n-------\n");