Note that there are some explanatory texts on larger screens.

plurals
  1. PObinary output in C++ and saving binary string in array
    primarykey
    data
    text
    <p>I've corrected the code:</p> <pre><code>//binary string input: if i enter abcd it gives its binary rep in 0's and 1's </code></pre> <p>secondly,i want to loop over the array when the binary string is being saved for instance:</p> <pre><code>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 &lt;&lt; "Please enter your msg :\n&gt;"; getline(cin, msg); //cout &lt;&lt; "You entered: " &lt;&lt; data; for(i=0;i&lt;=msg.size();i++){ for (j=0;j&lt;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&lt;8; k++,top--){ p_array[p]= m[top]; } cout &lt;&lt; array; return 0; } </code></pre> <p>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&lt;&lt; m[top] i get the binary form for abcd.</p> <p>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?</p> <p>why do i want to do this:</p> <p>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> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload