码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-03-10 23:09:54      阅读:189      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!