字节数组的合并
- byte[] defArr = File.ReadAllBytes(filePath);
- byte[] md5Arr = GetMd5Hash(filePath);
- int len = defArr.Length + md5Arr.Length;
- byte[] lenArr = BitConverter.GetBytes(len);
- if (BitConverter.IsLittleEndian)
- Array.Reverse(lenArr);
- //resArr为合并后数组
- byte[] resArr = new byte[lenArr.Length + defArr.Length + md5Arr.Length];
- lenArr.CopyTo(resArr, 0);
- md5Arr.CopyTo(resArr, lenArr.Length);
- defArr.CopyTo(resArr, lenArr.Length + md5Arr.Length);
浮点数转成字节数组:
const
string
formatter =
"{0,16:E7}{1,20}"
;
// Convert a float argument to a byte array and display it.
public
static
void
GetBytesSingle(
float
argument )
{
byte
[ ] byteArray = BitConverter.GetBytes( argument );
Console.WriteLine( formatter, argument,
BitConverter.ToString( byteArray ) );
}