-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxorwith0.c
48 lines (42 loc) · 859 Bytes
/
xorwith0.c
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
#include <stdio.h>
#include <string.h>
void binaryValue(int n) {
int b[8],x[8];
int j,k,l;
// Convert to binary
for ( j = 7; j >= 0; j--) {
b[j] = n % 2;
n = n / 2;
}
// Print binary representation
/* for (int i = 0; i < 8; i++) {
printf("%d\t", b[i]);
}*/
// printf("\n");
for( k=0;k<8;k++)
{
if(b[k]==0)
{
x[k]=0;
}
else{
x[k]=1;
}
}
int decimal = 0;
for ( l = 0; l < 8; l++) {
decimal = decimal * 2 + x[l];
}
printf("%c", (char)decimal);
}
int main() {
char str[100];
int i;
printf("Enter a String for Xor operation\n");
scanf("%s", str);
printf("After xor operation\n");
for ( i = 0; i < strlen(str); i++) {
binaryValue((int)str[i]);
}
return 0;
}