title: store a string in an int
body: <p>i try to store a string into an integer as follows:</p>
  
  <p>i read the characters of the string and every 4 characters i do this:</p>
  
  <pre><code>val = (int) ch &lt;&lt; 24 | (int) ch &lt;&lt; 16 | (int) ch &lt;&lt; 8 | (int) ch;
  </code></pre>
  
  <p>Then i put the integer value in an array of integer that is called memory (<code>=&gt; int memory[16]</code>).</p>
  
  <p>I would like to do it in an automatic way for every length of a string, plus i have difficulties to inverse the procedure again for an arbitrary size string. Any help?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>(from below)</p>
  
  <p>Basically, i do an exercise in JAVA. It's a MIPS simulator system. I have Register, Datum, Instruction, Label, Control, APSImulator classes and others. When i try to load the program from an array to simulator's memory, i actually read every contents of the array which is called 'program' and put it in memory. Memory is 2048 long and 32 bits wide. Registers are declared also 32bit integers. So when there is an content in the array like Datum.datum( "string" ) - Datum class has IntDatum and StringDatum subclasses - i have somehow to store the "string" in the simulator's data segment of memory. Memory is 0-1023 text and 1024-2047 data region. I also have to delimit the string with a null char - plus any checkings for full memory etc. I figure out that one way to store a String to MemContents ( reference type - empty interface - implemented by class that memory field belongs to ) is to store the string every ( 2 or maybe 4 symbols ) to a register and then take the contents of the register and store it in memory. So, i found very difficult to implement that and the reverse procedure also.</p>