首页 > 编程语言 > 详细

int 转换成 byte[] (byte数组)

时间:2015-03-10 23:09:14      阅读:296      评论:0      收藏:0      [点我收藏+]

unsigned int x = 1234567;
 byte*  intBytes = new byte[4];

 //方法一
 memcpy(intBytes, &x, sizeof(unsigned int));
 unsigned int y1 = intBytes[3] *256*256*256 + intBytes[2] *256*256 + intBytes[1]* 256 + intBytes[0];

 //方法二
 intBytes[0]   =   (byte)   (x   >>   24);
 intBytes[1]   =   (byte)   (x   >>   16);
 intBytes[2]   =   (byte)   (x   >>   8);
 intBytes[3]   =   (byte)   (x   >>   0);

 unsigned int y2 = intBytes[0] *256*256*256 + intBytes[1] *256*256 + intBytes[2]* 256 + intBytes[3];

 

int 转换成 byte[] (byte数组)

原文:http://blog.csdn.net/senophen/article/details/44183265

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!