title: Packing 4 bytes into an int
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2383265/convert-4-bytes-to-int">Convert 4 bytes to int</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to pack 4 bytes into an int using some of the solutions found here, but it doesn't seem to work for one of my tests.</p>
  
  <p>This is the code I'm using:</p>
  
  <pre><code>public static int pack(int c1, int c2, int c3, int c4)
  {
      return (c1 &lt;&lt; 24) | (c2 &lt;&lt; 16) | (c3 &lt;&lt; 8) | (c4);
  }
  </code></pre>
  
  <p>Now when I use it on something simple like 0x34, 0x68, 0x77, and 0x23 I get what I expect: 0x34687723. But when I use it on 0xBA, 0xAD, 0xBE, and 0xEF I get something way off. Does anyone see what the problem might be?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The above code was able to give me what I wanted, and the "wrong value" I mention below is just another way of representing 0xBAADBEEF in a decimal form.</p>