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?

有帮助吗?

解决方案

replace

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

with

   printf("%d\n",num1);
   printf("%d\n",num2);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top