Please help me in Binary XOR operation.... This program will ask user to enter their input..After that the program will convert to Binary Code for each character that user have entered. After that i create a multidimensional array to store for binary of each character...so from an array, i want to make a XOR operation for each binary..
Example :-
User Input : syahril
Binary for each character is :-
s = 01110011
y = 01111001
a = 01100001
h = 01101000
r = 01110010
i = 01101001
l = 01101100
So, my array will be like this
0 0 0 0 0 0 0
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 0 0 1 0 0
0 1 0 1 0 1 1
0 0 0 0 0 0 1
1 0 0 0 1 0 0
** the top row is the left most side for each character
** the bottom row is the right most side for each character
so...my program will do XOR operation for each binary in array start with top row from left to right...
so...when i executed and run my program it give to me an output like this = 00000000
but when i do a manual calculation for XOR operation based on the example, i will get an output like this = 01110100...
Please help me...i didnt know which part that im wrong or missing....
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
char *Entry, Letter, Choice[2];
int Ascii, len, Binary[8], Total;
void Convert();
int f = 0;
int Special[8][100];
int temp[100];
int hold[100];
int k =0;
int s=2;
int z=1;
int h=2;
int m=1;
int x=0;
int u=0;
int y = 0;
int result[8];
int la = 0;
int temp_len;
void main()
{
Convert();
}
void Convert()
{
Entry = new char[501];
cout << "Enter Text To Convert(Up To 500 Chars): ";
cin.getline(Entry, 500);
len = strlen(Entry);
temp_len = len;
cout<<"\n\n";
for(int d = 0; d < len; d++)
{
Total = 7;
Letter = Entry[d];
Ascii = Letter;
while(Ascii > 0)
{
if((Ascii%2)==0)
{
Binary[Total] = 0;
Ascii = Ascii/2;
Total--;
}
else
{
Binary[Total] = 1;
Ascii = Ascii/2;
Total--;
}
}
for(int e = 0; e < 8; e++)
{
cout << Binary[e];
Special[e][f] = Binary[e];
}
f++;
cout<<"\n\n";
}
cout<<"\n\nThe output Display in Array : \n\n";
for(int l=0;l<8;l++)
{
hold[y]=Special[l][y];
if(hold[y]==Special[l][k++])
{
temp[z]=0;
while(s<len)
{
if(temp[z]==Special[l][h])
{
temp[m++]=0;
h++;
}
else
{
temp[m++]=1;
h++;
}
s++;
z++;
}
}
else
{
temp[z]=1;
while(s<len)
{
if(temp[z]==Special[l][h])
{
temp[m++]=0;
h++;
}
else
{
temp[m++]=1;
h++;
}
s++;
z++;
}
}
result[u] = temp[temp_len--];
u++;
k=0;
s=2;
z=1;
h=2;
m=1;
y=0;
temp_len = len;
}
while(la<8)
{
for(int oop = 0;oop <len;oop++)
{
cout<<Special[la][oop]<<" ";
}
la++;
cout<<"\n\n";
}
cout<<"\n\nThe result for XOR operation is : \n";
for(int t=0;t<8;t++)
{
cout<<result[t];
}
cout<<"\n\n";
delete[] Entry;
}
|