如果涉及 big_endian 和 little_endian 变化,则互换两个字节即可
short A[10]; unsigned char B[20]; memcpy( B, A, 20 ); 清空数组 int A[10] memset(A, 0, sizeof(A)); 2. 3. 4. 5. 6. 7. 8.
char *p = new char[100];unsigned char *pU = static_cast(p);
publicstaticshortbyteArray2short(byte[] b,intindex) { return(short) (((b[index +1] <<8) | b[index +0] &0xff)); } byte[]和char的互转 /** * 字符到字节转换 * * @param ch * @return */ publicstaticvoidchar2byteArray(byte[] bb,charch,intindex) { inttemp = (int) ch; //...
TA贡献1725条经验 获得超7个赞
用内存copy方法吧 short A[10];unsigned char B[20];memcpy( B, A, 20 );
* 通过byte数组取到short * * @param b * @param index 第几位开始取 * @return */ public static short getShort(byte[] b, int index) { return (short) (((b[index + 1] << 8) | b[index + 0] & 0xff)); } byte和char类型的转换 ...