'바꾸는법'에 해당되는 글 1

  1. 2013.10.25 Integer값 , short값을 byte배열로 넣는법

펌 OK (출처 표시), 상업적 이용 NO, 컨텐츠 변경 NO

public static byte[] shortToByte(short a) {

byte[] shortToByte = new byte[2];

shortToByte[0] |= (byte)((a & 0xFF00) >>> 8);

shortToByte[1] |= (byte)(a & 0xFF & 0xff);

return shortToByte;

}  

   public static byte[] intToByte(int a) {  

     byte[] intToByte = new byte[4];     

     intToByte[0] |= (byte)((a&0xFF000000)>>24);     

     intToByte[1] |= (byte)((a&0xFF0000)>>16);     

     intToByte[2] |= (byte)((a&0xFF00)>>8);     

     intToByte[3] |= (byte)(a&0xFF);   

     return intToByte;  

   }  


-끝-