implement isPalindrome(int n)
1,441.7K Views
Implement the function boolean isPalindrome (int n); Which will return true if the bit-wise representation of the integer is a palindrome and false otherwise.
bool
isNthBitSet(unsigned
int
x, unsigned
int
n)
{
return
(x & (1 << (n-1)))?
true
:
false
;
}
bool
isPalindrome(unsigned
int
x)
{
int
l = 1;
// Initialize left position
int
r =
sizeof
(unsigned
int
)*8;
// initialize right position
// One by one compare bits
while
(l < r)
{
if
(isNthBitSet(x, l) != isNthBitSet(x, r))
return
false
;
l++;
r--;
}
return
true
;
}
Your Answer
More puzzles to try-
The more I am used, the thinner I grow
I am not clothes but I cover your body; The more I am used, the thinner I grow. What am ...Read More »Chocolates Bricks Riddle
How many steps are required to break an m × n sized bar of chocolate into 1 × 1 pieces? ...Read More »What does this funny rebus riddle means ?
Tell The Number Of Chickens
How Many Chicken Maths Problem A farmer sold a few chickens to four different customers on a particular day. It ...Read More »Biggest number using four 3s Puzzle
What should be the biggest number being formed using Four 3s according to you? Think Big! Bigger! and the Biggest!!!!Read More »In the house through keyhole
What always comes into a house through the keyhole?Read More »Matchstick Game
Can you find out a way through which you can make five squares out of the given figure by moving ...Read More »Police Investigation
A man is found dead with a knife wound to the chest in a round house. Police investigation was narrowed ...Read More »Let’s check your presence of mind…..
In this question four words are given, out of which three are same in a certain way while the rest ...Read More »Missing Numbers
Find the missing value:Read More »Day, week and year easy logical puzzle
What occurs, twice in a week, once in a year, but never in a day?Read More »It Comprises Roots
It comprises roots which nobody sees, Much taller than those trees, Up and up it goes, Still, it never grows.Read More »A Farmer, a Wolf, A Goat, and a Cabbage
A farmer went to a market and bought a wolf, a goat, and a cabbage. On his way home, the ...Read More »I am in the Earth and the heaven. What am I?
I am the first in the earth. Second in heaven. I appear twice in a week, though you can only ...Read More »never rude for you
I never be rude for you, Though I flag my tongue for all to see. Who am I?Read More »How can you make?
How can you make a TV, a bed, a dog, and a car liquid?Read More »Jump out of plane riddle
One day a man jumped from a plane without a parachute and suffered no injuries, how is that possible?Read More »What will she name her next child ?
A pregnant woman is preparing to name her seventh child. Her children’s names so far are Dominique, Regis, Michelle, Fawn, ...Read More »Horseshoe tricky riddle
If the horseshoe is in the barn, is it March?Read More »Always Rocks
It is the first thing you see in the morning and the last thing you see at night, It is ...Read More »
Accenture Interview PuzzlesAdobe Interview PuzzlesAge RiddleAkbar Birbal PuzzlesAlgorithm PuzzlesAlphabet riddleAmazon Interview PuzzlesAnalytical MathematicsAptitude PuzzleBank PuzzlesBetting PuzzlesBrain TeasersCalendar PuzzlesCards PuzzlesChess Board PuzzleChess PuzzlesChristmas Puzzlecipher PuzzleCivil Services PuzzleClock time puzzleCognizant Interview PuzzlesCoins PuzzleComputational PuzzleconundrumCoronavirus PuzzleCoupondunia Interview PuzzleCritical Thinking Puzzledata analyticsData Structure Interview QuestionsDecode PuzzleDetective PuzzlesDice PuzzleDictionary Riddlesdifficult riddleEasy Math puzzlesEasy puzzlesEinstein puzzleEnglish RiddleFamily Tree Puzzlefamous puzzleFill in the blanks riddlesFinding Killer RiddlesFlipkart interview puzzlesFunny RiddlesGeneral KnowledgeGeographical PuzzleGoogle Code Jam 2014Google Interview PuzzlesGRE PuzzleHard Puzzle