Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
'gives an error', what error, what line of code? What does 'my binary string of zeros and 1s declared under type int' mean? Are you using a string or an int, it's not clear. –  john Nov 8 '13 at 17:15
1  
The code you have posted has multiple syntax errors, none of which have anything to do with the question you have asked. If that is your real code then fix the syntax errors first, for (k=0, j=7; k<=7; k++, j--) for instance and array[k] = m[j];} –  john Nov 8 '13 at 17:18
    
Is your binary string big endian or little endian in bits? –  nio Nov 8 '13 at 17:18
    
the string comes from ascii conversion to binary. –  user899714 Nov 8 '13 at 17:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.