-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvancedBitManipulation.cpp
98 lines (91 loc) · 2.04 KB
/
AdvancedBitManipulation.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <math.h>
using namespace std;
int bitcounter(int arr[] , int number)
{ int ctr = 0 ;
while (number > 0)
{
if ( number & 1 == 1 )
{
arr[ctr]++ ;
}
number = number >> 1 ;
ctr++;
}
return 0 ;
}
int main()
{
int arr[] = {0,0,0,0,0,0,0,0,0,0};
int arr3[] = {2,2,1,5,1,1,2};
for(int i=0;i<7 ;i++)
{
bitcounter(arr,arr3[i]);
}
for (int i =0 ; i<10 ;i++)
{
cout<<arr[i]<<"**";
}
cout<<endl;
for (int i =0 ; i<10 ;i++)
{
if ( arr[i] >=3 )
{
arr[i] = arr[i] % 3 ;
}
}
for (int i =0 ; i<10 ;i++)
{
cout<<arr[i]<<"**";
}
int binry = 0 ;
for (int i =0 ; i<10 ;i++)
{
if (arr[i] ==1)
{
binry = binry + pow(2,i);
}
}
cout<<binry;
// int arr1[] = {5, 6, 7, 5, 6, 7, 1, 3, 3};
// int x = 0;
// int length = sizeof(arr1)/sizeof(arr1[0]);
// for (int i = 0; i < length; i++)
// {
// x = arr1[i] ^ x;
// }
// cout << x;
//********************************************************************************************************//
// int arr2[] = {5, 6, 7, 2, 5, 6, 7, 9, 3, 3};
// int y = 0;
// int length2 = sizeof(arr2)/sizeof(arr2[0]);
// for (int i = 0; i < length2; i++)
// {
// y = arr2[i] ^ y;
// }
// int temp = y;
// int temp2 = y;
// int temp3 = y;
// int counter = 0;
// while (temp > 0)
// {
// if (temp & 1 == 1)
// break;
// temp = temp>>1;
// counter++;
// }
// for (int j =0 ;j <length2 ; j++)
// {
// if ((arr2[j]>>counter) & 1 == 1)
// {
// temp2 = arr2[j] ^ temp2 ;
// }
// else
// {
// temp3 = arr2[j] ^ temp3 ;
// }
// }
// cout<<temp2<<"***"<<temp3;
//********************************************************************************************************//
return 0;
}