1. 程式人生 > >Android開發:int型別資料按照高低位,存放到byte型別的陣列

Android開發:int型別資料按照高低位,存放到byte型別的陣列

int型別的資料—>byte型別陣列轉換

//byte陣列"按高位在前,低位在後"的方式存放int型別資料
int src = 123;
int[] dec = new int[4];
dec[0] = (src /256/256/256);
dec[1] = (src /256/256);
dec[2] = (src /256);
dec[3] = (src %256);
//byte陣列按"低位在前,高位在後"的方式存放int型別資料
int src = 123;
int[] dec = new int[4];
dec[0] = (src %256);
dec[1] = (src /256
); dec[2] = (src /256/256); dec[3] = (src /256/256/256);