使用Memcopy进行八位char 跟十六位的short之间的转化
张亚成 2014-04-29 05:39:40 在程序中有时候需要把十六位的short数组转化成八位的char数组,有时候需要把八位的char数组转化成十六位的short数组,看到别的程序上写的是使用memcopy就完成了,
如:
char ch【4】 = {0x01,0x02,0x03,0x04};
short sh[2];
memcopy(sh, ch, 4);
此时 : sh[2] = {0x0102, 0x0304}
但是我总感觉这个使用方法可能会不妥 ?请大家帮忙指点一下。