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


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

查看所有标签

猜你喜欢:

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

The Dream Machine

The Dream Machine

M. Mitchell Waldrop / Penguin Books / 2002-8 / USD 16.00

While most people may not be familiar with the name J. C. R. Licklider, he was the guiding spirit behind the greatest revolution of the modern era. At a time when most computers were big, ponderous ma......一起来看看 《The Dream Machine》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具