1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Let’s check to see if a number is a palindrome. For each challenge, you can use any operator allowed in the integer problems in datalab. Using 1 operator, we return the 1 if the number is a palindrome, 0 otherwise: 4. How about if there are two bits in the input? (5 ops max) int isPalindrome2bit(int x) { int hibit = __________; int lobit = ___________; return !(_______ ^ lobit); } 5. How about if there are four bits? (10 ops max) int isPalindrome4bit(int x) { int mask2 = _________; int hi2 = ___________; int lo2 = ___________; int mask1 = ___________; int newhi1 = (____ & ____) << _____; int newlo1 = (____ >> ____) & _____; int lo2Reverse = newhi1 | ________; return !(___________ ^ ___________); } 6. How about if there are eight bits? (15 ops max) int isPalindrome8bit(int x) { int mask4 = _________; int hi4 = ___________; int lo4 = ___________; int mask2 = _________; int newhi2 = ___________; int newlo2 = ___________; int lo4R2 = _____ | _____; int mask1 = ___________; int newhi1 = ____________; int newlo1 = ____________; int lo4R4 = _____ | _____; return !(___________ ^ ___________); }
|