I've corrected the code:
//binary string input: if i enter abcd it gives its binary rep in 0's and 1's
secondly,i want to loop over the array when the binary string is being saved for instance:
int main() {
string msg;
int i;
int j;
int k;
int m[8];
int array[100];
int s;
int p_array[100];
// Taking a string as input from user............................................input
cout << "Please enter your msg :\n>";
getline(cin, msg);
//cout << "You entered: " << data;
for(i=0;i<=msg.size();i++){
for (j=0;j<8;j++){
m[j]= msg[i] % 2; //remainder gives us binary value
msg[i] = msg[i]/2;
}
int top, k,p;
for(k=0,top =7; k<8; k++,top--){
p_array[p]= m[top];
}
cout << array;
return 0;
}
problem1: The output gives me this value for abcd = 0x22fbd0. why? i want the value in binary. if i dont use the array and only take cout<< m[top] i get the binary form for abcd.
problem 2: i want to fill the p_array this way: the next 8 bits after array is filled from top = 7 to 0, to start filling in from position 8 in array, and then the next 8 bits after that from position 15 and so on. how should i make that possible?
why do i want to do this:
because after this is done, then from the entire p_array i need to pick 16 bits at a time and save it to a new array this way:
p_array (first 16 bits) + new array (0 initially) = newarray next 16 bits from p_array + new array = newarray .....and so on till i get the final sum in new array.
for (k=0, j=7; k<=7; k++, j--)
for instance andarray[k] = m[j];}
– john Nov 8 '13 at 17:18