c# – 将int复制到byte []的最简单方法

栏目: ASP.NET · 发布时间: 7年前

内容简介:我有一个byte [],我正在遍历一个int(和其他数据)列表,我想将int复制到我的byteArray [index * 4]我该怎么做?翻译自:https://stackoverflow.com/questions/1287143/simplest-way-to-copy-int-to-byte

我有一个byte [],我正在遍历一个int(和其他数据)列表,我想将int复制到我的byteArray [index * 4]我该怎么做?

BitConverter

很可能是你的朋友.

但是,这通常会返回一个新的字节数组.它也不允许您指定字节顺序.我在 MiscUtil 中有EndianBitConverter类,它具有通过将数据直接复制到现有字节数组来转换基元类型的方法.

例如:

// Copy the bytes from the integer "value" into a byte array
// (buffer) starting at index 5
EndianBitConverter.Little.CopyBytes(value, buffer, 5);

翻译自:https://stackoverflow.com/questions/1287143/simplest-way-to-copy-int-to-byte


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Pro CSS and HTML Design Patterns

Pro CSS and HTML Design Patterns

Michael Bowers / Apress / April 23, 2007 / $44.99

Design patterns have been used with great success in software programming. They improve productivity, creativity, and efficiency in web design and development, and they reduce code bloat and complexit......一起来看看 《Pro CSS and HTML Design Patterns》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具