-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.cpp
More file actions
64 lines (52 loc) · 873 Bytes
/
Copy pathOperators.cpp
File metadata and controls
64 lines (52 loc) · 873 Bytes
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
#include <iostream>
#include <string>
using namespace std;
void display(string &s)
{
for (auto x : s)
{
cout << x << ' ';
}
cout << endl;
}
int binaryToDecimal(string &s)
{
int result = 0;
int n = s.size();
for (int i = n - 1; i >= 0; i--)
{
if (s[i] == '1')
{
int x = pow(2, n - i - 1);
result += x;
}
}
return result;
}
string decimalToBinary(int n)
{
if(n == 0) return "0";
string result;
while (n != 1)
{
if (n % 2 == 1)
{
result.push_back('1');
}
else
{
result.push_back('0');
}
n = n / 2;
}
result.push_back('1');
reverse(result.begin(), result.end());
return result;
}
int main()
{
int x = INT_MIN;
x = ~x;
cout << x;
return 0;
}