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
|
530 Discussions
|
Please Login in order to post a comment
include
include
include
include
void calculate_the_maximum(int n, int k) { int max_and = 0, max_or = 0, max_xor = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int temp_and = i & j; int temp_or = i | j; int temp_xor = i ^ j; if (temp_and > max_and && temp_and < k) { max_and = temp_and; } if (temp_or > max_or && temp_or < k) { max_or = temp_or; } if (temp_xor > max_xor && temp_xor < k) { max_xor = temp_xor; } } } printf("%d\n%d\n%d", max_and, max_or, max_xor); }
int main() { int n, k;
}
Passed all Testcases
In the description of the the problem it lists the answer to the sample problem as
2,3,3 However, the answer is 3,3,3 from my output, for i in 1 through n, find the maximum value of the logical and, or and xor when compared againt all integers through n that are greater than i. Consider a value only if the comparison returns a result less than .... The first combination is 1,2 and that gives 0,3,3 which makes the first number 3
include
int main() { // a = 5 (00000101 in 8-bit binary), b = 9 (00001001 in // 8-bit binary) unsigned int a = 1, b = 2; unsigned int c=23; // The result is 00000001 printf("a = %u, b = %u\n", a, b); printf("a&b = %u\n", a & b); // The result is 00001101 printf("a|b = %u\n", a | b); // The result is 00001100 printf("a^b = %u\n", a ^ b); printf("~a = %u\n", a = ~a); // The result is 00010010 printf("b<<1 = %u\n", b << 1); printf("a>>b = %u\n", a >> b); // The result is 00000100 printf("b>>1 = %u\n", b >> 1); printf("a|b^a= %u\n", b|c); return 0; }
yeilds:
a = 1, b = 2 a&b = 0 a|b = 3 a^b = 3 ~a = 4294967294 b<<1 = 4 a>>b = 1073741823 b>>1 = 1 a|b^a= 23
Also there is no scroll bar on this text window for me so I can't edit it properly.
void calculate_the_maximum(int n, int k) { int a, b; int AND, OR, XOR; int maxAND = 0; int maxOR = 0; int maxXOR = 0;
}
int main() { int n, k;
}