public int BytestoInt(byte[] byteInt)
 {
  int result = 0;
  for (int i = 0; i < 4; i++)
  {
   result = result << 4;
   result = result | ( (byteInt[i] >> 4) & 0x0F);
   result = result << 4;
   result = result | (byteInt[i] & 0x0F);
  }
  return result;
 }
public byte[] intToBytes(int iData)
 {
  byte[] result = new byte[4];
  result[0] = (byte) (iData >>> 24 & 0xff);
  result[1] = (byte) (iData >>> 16 & 0xff);
  result[2] = (byte) (iData >>> 8 & 0xff);
  result[3] = (byte) (iData >>> 0 & 0xff);
  return result;
 }


 

위와 같은 메소드를 만들어서 사용하고 있는데요

 

바이트배열로 변환한 인트를 다시 인트로 변환할때 값이 틀리게 나오더군요

 

예를들면 20092 를 바이트로 변환하여 저장하면 [52, 101, 55, 99] 과 같이 저장되는데 이게 맞는지도 잘 모르겠고...

 

이 것을 다시 인트로 변환하면 879048547 와 같은 말도 안되는 -_- 숫자가 나옵니다.

 

왜이럴까요?