BitConverter

将基础数据类型与字节数组相互转换。

此类便于操作基本形式的类型。一个字节定义为一个 8 位无符号整数。

此类型的任何公共 static 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

使用BitConverter对int与byte[]类型进行互相转换
int转换到byte[]

int iCount = 45;
byte[] byInputData = BitConverter.GetBytes(iCount);

byte[]转换回int

int iCount = BitConverter.ToInt32(byInputData, 0);

原文地址:https://www.cnblogs.com/zxhoo/p/2003879.html