如何将int类型数据转换成byte数组
生活随笔
收集整理的這篇文章主要介紹了
如何将int类型数据转换成byte数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public byte[] intTobytes(int number,byte[] source)
? {
??? byte [] ret=null;
??? if(source.length<2)
????? ret = new byte[2];
??? else
????? ret = source;
??? //converter here
???? ret[0]=(byte)(number&0xff);
???? ret[1]=(byte)((number>>8)&0xff);//還可以轉換成4個字節的。
??? return ret;
? }
? {
??? byte [] ret=null;
??? if(source.length<2)
????? ret = new byte[2];
??? else
????? ret = source;
??? //converter here
???? ret[0]=(byte)(number&0xff);
???? ret[1]=(byte)((number>>8)&0xff);//還可以轉換成4個字節的。
??? return ret;
? }
轉載于:https://www.cnblogs.com/tuyile006/archive/2006/06/23/434083.html
總結
以上是生活随笔為你收集整理的如何将int类型数据转换成byte数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: office2007的界面
- 下一篇: JavaScript 学习(2) - J