Question

I'm trying to compute bitwise | only using & and ~.

   int main() {

   int num1 = 3;
   int num2 = 6;

   printf("%d\n",num1|num2); 

   num1 = ~num1;
   num2 = ~num2;

   printf("d\n",num1);
   printf("d\n",num2);

   int num3 = num1 & num2;    

   printf("%d\n",num3); 

}

And here is the output:

7
d
d
-8

I'm trying to figure out why ~num1 is outputting d?

Was it helpful?

Solution

replace

   printf("d\n",num1);
   printf("d\n",num2);

with

   printf("%d\n",num1);
   printf("%d\n",num2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top