forked from altruistcoder/Data-Structures-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check Binary Representation is Palindrome
- Loading branch information
1 parent
303316b
commit 75d3387
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def binaryPalindrome(num): | ||
rev = 0 | ||
n1 = num | ||
while n1 > 0: | ||
rev <<= 1 | ||
if (n1 & 1) == 1: | ||
rev ^= 1 | ||
n1 >>= 1 | ||
return num == rev | ||
|
||
n = int(input("Enter a number: ")) | ||
if binaryPalindrome(n): | ||
print("The given number's binary representation is palindrome") | ||
else: | ||
print("The given number's binary representation is not palindrome") |