-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitt.cpp
More file actions
89 lines (44 loc) · 1.14 KB
/
bitt.cpp
File metadata and controls
89 lines (44 loc) · 1.14 KB
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
#include <stdio.h>
#include <stdlib.h>
void printBit (unsigned int);
int setBit(int, int);
int checkone (int n){
int c1=0;
while ( (n&1)==1){
c1++; n>>1;
}
return 0;
}
int main(){
unsigned int k,t ;
int s = sizeof (unsigned int);
unsigned int pow = 1<<(s*8-1);
printBit(pow);
while (scanf("%d",&k)!=EOF){
printBit(k);
scanf("%d", &t);
printf("%d\n", setBit(k,t));
printBit(setBit (k,t));
checkone(k);
}
return 0;
}
void printBit (unsigned int n){
int s = sizeof (unsigned int);
unsigned int pow = 1<<(s*8-1);
//printf("%d\n",pow);
while (pow){
int a=((n &pow)?1:0);
printf("%u", a);
// n>>=1;
// n<<=1;
pow>>=1;
if(pow==0) printf("\n");
//printf("rn=%d\n",n);
//printf("power=%d\n",pow);
}
}
int setBit (int i, int j){
int p = 1<<j;
return i|p;
}