File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -138,3 +138,7 @@ This is a repository containing various C++ Programs to understand the basic con
138
138
139
139
C++ Code for removing duplicate elements present in a sorted array.
140
140
141
+ * [ Check Binary Representation of a number is Palidrome or not] ( https://github.com/altruistcoder/Data-Structures/blob/master/binary_palindrome.cpp ) :
142
+
143
+ C++ Code for checking whether binary representation of a number is palindrome or not.
144
+
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ bool binaryPalindrome (int num)
5
+ {
6
+ long n1=num, rev=0 ;
7
+ while (n1>0 )
8
+ {
9
+ rev <<= 1 ;
10
+ if ((n1&1 )==1 )
11
+ rev ^= 1 ;
12
+ n1 >>= 1 ;
13
+ }
14
+ return num==rev;
15
+ }
16
+
17
+ int main ()
18
+ {
19
+ long n;
20
+ cout<<" Enter a number: " ;
21
+ cin>>n;
22
+ if (binaryPalindrome (n))
23
+ cout<<" The given number's binary representation is palindrome" ;
24
+ else
25
+ cout<<" The given number's binary representation is not palindrome" ;
26
+ }
You can’t perform that action at this time.
0 commit comments