-
Notifications
You must be signed in to change notification settings - Fork 1
/
BinaryConversion.cpp
76 lines (58 loc) · 1.4 KB
/
BinaryConversion.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<math.h>
using namespace std;
bool paliendrome(long long int a)
{
long long dup,rev=0;
dup=a;
while(dup>0)
{
rev=(rev*10)+(dup%10);
dup/=10;}
if(rev==a)
return true;
else
return false;
}
bool binary(long long int num)
{
long long i=1;
long digit=1,bin[100000],d;
while(num>0)
{
bin[0]=num%2;
num/=2;
digit++;
d=digit;
while(d>0)
{
bin[d]=bin[d-1];
d--;} }
d=1;
digit-=1;
cout<<"BINARY FORM =";
for(long long k=1;k<=digit;k++)
{
cout<<bin[k];}
cout<<"\n";
while(d<digit)
{
if(bin[d]!=bin[digit])
return false;
d++;
digit--;
}
return true;
}
int main()
{
long long i;
cout<<"ENTER THE NUMBER\n\n\t?=";
cin>>i;
if(binary(i))
cout<<i<<" IS PALIENDROME IN BASE-2";
else
cout<<i<<" IS NOT A PALIENDROME IN BASE-2";
cin>>i;
return 0;
}