Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Bitwise Operators Questions
Assume 16-bit signed int: what hexadecimal is printed for this arithmetic right shift? #include
int main() { printf("%x ", -1 >> 1); return 0; }
Bit masking and shifts in C: evaluate the expression and print the result. #include
int main() { unsigned int res; res = (64 >>(2 + 1 - 2)) & (~(1 << 2)); printf("%d ", res); return 0; }
ASCII and bitwise OR on character codes: what five characters are printed? #include
int main() { char c = 48; // ASCII '0' int i, mask = 01; // octal 1 for (i = 1; i <= 5; i++) { printf("%c", c | mask); mask = mask << 1; } return 0; }
Operator precedence with bitwise and logical operators: predict the three integers printed. #include
int main() { int i = 4, j = 8; printf("%d, %d, %d ", i | j & j | i, i | j && j | i, i ^ j); return 0; }
Bitwise OR, AND, and XOR with identical values in decimal and hex: compute and print all results. #include
int main() { int i = 32, j = 0x20; int k, l, m; k = i | j; l = i & j; m = k ^ l; printf("%d, %d, %d, %d, %d ", i, j, k, l, m); return 0; }
In C programming (assuming unsigned int is 2 bytes = 16 bits), what will this program print in hexadecimal?\n\n#include
\n\nint main()\n{\n unsigned int a = 0xffff; // 16-bit all 1s\n ~a; // bitwise NOT result is not stored back\n printf("%x\n", a);\n return 0;\n}\n\nChoose the exact output produced by printf.
In C (unsigned int is 2 bytes = 16 bits), evaluate the effect of bitwise NOT on 32 and determine the printed hexadecimal value:\n\n#include
\n\nint main()\n{\n unsigned int m = 32; // 0x0020 on 16 bits\n printf("%x\n", ~m);\n return 0;\n}\n\nSelect the exact output.
In C, consider missing arguments to printf: what will actually be printed (conceptually) by this code using bit shifts?\n\n#include
\n\nint main()\n{\n printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);\n return 0;\n}\n\nNote: The format string has four %d placeholders but only two arguments.
Evaluate this macro-based C program: what integer does it print?\n\n#define P printf("%d\n", -1 ^ ~0)\n#define M(P) int main()\\n {\\n P\\n return 0;\\n }\nM(P)\n\nAssume typical two’s-complement semantics.
Bit shifts with negative counts in C: determine the safest conclusion about this program’s outputs (assume typical hosted C, int is 32 bits).\n\n#include
\n\nint main()\n{\n printf("%d %d\n", 32<<1, 32<<0);\n printf("%d %d\n", 32<<-1, 32<<-0);\n printf("%d %d\n", 32>>1, 32>>0);\n printf("%d %d\n", 32>>-1, 32>>-0);\n return 0;\n}\n\nNote: shifting by a negative amount is not defined by the C standard.
Assuming a 2-byte (16-bit) int in C, what hexadecimal value is printed here?\n\n#include
\n\nint main()\n{\n printf("%x\n", -1 << 3);\n return 0;\n}\n\nPick the most appropriate result given typical two’s-complement behavior.
Given unsigned char i = 0x80 in C, what decimal value is printed?\n\n#include
\n\nint main()\n{\n unsigned char i = 0x80; // 128\n printf("%d\n", i << 1);\n return 0;\n}\n\nAssume usual integer promotions apply before the shift.
Concept check: In C, are the bitwise operators & and | unary operators or binary (dyadic) operators?
Reasoning about left shifts: Is left-shifting an integer by 1 always equivalent to multiplying it by 2 in C?\nAnswer considering overflow and signedness rules.
Bitwise AND for division: Can the bitwise & operator be used to divide an integer by powers of 2 in C?\nChoose the correct statement.
In C/C++, can the bitwise AND operator (&) be used to test whether more than one bit is set in an integer?\n\nGive a precise, programming-focused answer and consider common idioms such as x & (x - 1) to detect if multiple bits are on.
Right shifting a negative (signed) integer: does the result vary across systems when using expression1 >> expression2 if the sign bit is 1?
Using bitwise AND (&) with a mask to test whether a specific bit is set in an integer: is this a valid and standard technique?
Is left shifting an unsigned int or unsigned char by 1 always equivalent to multiplying by 2 (in practical C/C++ code)?
When you left shift an integer in C/C++, do the leftmost bits “rotate” around to the right side (i.e., is a left shift a rotate)?
1
2