Using a 1 bit variable determine if a number is a numeric palyndrome
Anonymous
I assume you mean a binary palindrome, such as 1001001. The main idea is: 1. Check the number limits (highest '1') 2. Iterate from both size and check if bits different. Adding JAVA code. public static boolean isPalindrome(int num){ // Find highest '1' int temp = num, size=0; while(temp!=0){ size++; temp=temp>>1; } // Compare each left-right bit for (int i=0; i> i & 0x1) != (num >> (size-i-1) & 0x1)) return false; } return true; }
Check out your Company Bowl for anonymous work chats.