`

byte[]&int&long

 
阅读更多

参考:http://blog.csdn.net/defonds/article/details/8782785

int 值和byte[]数组直接的转换:

 

  1. public static int byteArrayToInt(byte[] b) {  
  2.     return   b[3] & 0xFF |  
  3.             (b[2] & 0xFF) << 8 |  
  4.             (b[1] & 0xFF) << 16 |  
  5.             (b[0] & 0xFF) << 24;  
  6. }  
  7.   
  8. public static byte[] intToByteArray(int a) {  
  9.     return new byte[] {  
  10.         (byte) ((a >> 24) & 0xFF),  
  11.         (byte) ((a >> 16) & 0xFF),     
  12.         (byte) ((a >> 8) & 0xFF),     
  13.         (byte) (a & 0xFF)  
  14.     };  
  15. }  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics