首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >C++整数到字节数组

C++整数到字节数组
EN

Stack Overflow用户
提问于 2011-04-08 02:05:46
回答 8查看 136.6K关注 0票数 36

我在我的java代码中有这个方法,它返回给定int的字节数组:

代码语言:javascript
复制
private static byte[] intToBytes(int paramInt)
{
     byte[] arrayOfByte = new byte[4];
     ByteBuffer localByteBuffer = ByteBuffer.allocate(4);
     localByteBuffer.putInt(paramInt);
     for (int i = 0; i < 4; i++)
         arrayOfByte[(3 - i)] = localByteBuffer.array()[i];
     return arrayOfByte;
}

有人能给我一些提示吗?我怎样才能把这个方法转换成C++?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5585532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档