We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Bitwise Operators
Bitwise Operators
Sort by
recency
|
570 Discussions
|
Please Login in order to post a comment
Bitwise operations can be tricky at first, but breaking them down like this with binary representations really helps. Perfect for anyone learning C or diving into low-level programming concepts! Play Exchange Login
{ int max_and = 0, max_or = 0, max_xor = 0;
}
include
int main() { int n,k; scanf("%d %d", &n, &k); int b=2, a=1,real_b = 0, max_or=0, max_and=0,max_xor=0; for(a; a<=n; a++){ if(a==b){ b++; } real_b=b; for(b; b<=n; b++){ int and=0, or=0, xor=0; and = a&b; or = a | b; xor = a ^ b; if(and>max_and && andmax_or && ormax_xor && xor < k){ max_xor = xor; }
}
void calculate_the_maximum(int n, int k) { int i,j,and,or,xor,M1=0,M2=0,M3=0; for(i=1;i
} printf("%d\n",M1); printf("%d\n",M2); printf("%d\n",M3); }