java int转byte,long转byte
View Code
byte[] returnInt = new byte[4]; returnInt[0] = (byte)((intValueParm >>> 24) & 0xFF); returnInt[1] = (byte)((intValueParm >>> 16) & 0xFF); returnInt[2] = (byte)((intValueParm >>> 8) & 0xFF); returnInt[3] = (byte)((intValueParm >>> 0) & 0xFF); return returnInt;
long转换为byte的时候:
View Code
byte[] returnInt = new byte[8]; returnInt[0] = (byte)((longValueParm >> 56) & 0xFF); returnInt[1] = (byte)((longValueParm >>> 48) & 0xFF); returnInt[2] = (byte)((longValueParm >>> 40) & 0xFF); returnInt[3] = (byte)((longValueParm >>> 32) & 0xFF); returnInt[4] = (byte)((longValueParm >>> 24) & 0xFF); returnInt[5] = (byte)((longValueParm >>> 16) & 0xFF); returnInt[6] = (byte)((longValueParm >>> 8) & 0xFF); returnInt[7] = (byte)((longValueParm >>> 0) & 0xFF); return returnInt;
这段代码是一个同事写的,各种百度才看懂!基础知识不过关啊