GATE Computer ScienceHardGATE CS (PYQ pattern)
unsigned char rev(unsigned char x) { unsigned char r = 0; for (int i = 0; i < 8; i++) { r = (r << 1) | (x & 1); x >>= 1; } return r; } unsigned char rotl(unsigned char x, int k) { return (unsigned char)((x << k) | (x >> (8 - k))); } What is the decimal value of rotl(0x2D, 3) ^ rev(0x2D)?
- A. 220
- B. 68
- C. 17
- D. 221
Correct answer: D. 221
0x2D = 0010 1101. Rotating left by 3 moves the top three bits 001 to the bottom: 0110 1001 = 0x69. Reversing the bit order gives 1011 0100 = 0xB4. XOR: 0110 1001 ^ 1011 0100 = 1101 1101 = 221. A plain shift (losing the top bits) gives 220.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Assume 4-byte int and 8-byte pointers. char s[] = "ab0cd"; char p = "ab0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s)…
- For a BST built from distinct keys (deletion of a node with two children uses its inorder successor), consider: I. Inserting a new key and…
- A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A…
- A DAG on vertices 1..7 has edges 1->2, 1->3, 2->4, 3->4, 3->5, 4->6, 5->6, 7->5. How many distinct topological orderings does it have?
- Union-find on elements 1..12 (initially separate) uses union by size (the root of the larger set becomes the parent; on a tie the root of…
- A 3-ary max-heap with 100 elements is stored in a 0-indexed array (the children of i are 3i + 1, 3i + 2, 3i + 3). How many leaves does it…