我正在写一个二进制文件转换器,我需要将1-6字节的数组转换为int(short-long)值。目前我正在使用以下三个功能,但我想知道是否有改进性能的方法?如何提高将byte []转换为int的性能?
private string byteToShortParse(byte[] recordData, int offset, int length)
{
byte[] workingSet = new byte[2];
Buffer.BlockCopy(recordData, offset, workingSet, 0, length);
return (BitConverter.ToInt16(workingSet, 0).ToString());
}
private string byteToIntParse(byte[] recordData, int offset, int length)
{
byte[] workingSet = new byte[4];
Buffer.BlockCopy(recordData, offset, workingSet, 0, length);
return (BitConverter.ToInt32(workingSet, 0).ToString());
}
private string byteToLongParse(byte[] recordData, int offset, int length)
{
byte[] workingSet = new byte[8];
Buffer.BlockCopy(recordData, offset, workingSet, 0, length);
return (BitConverter.ToInt32(workingSet, 0).ToString());
}
如果你正在处理的字节真的没有太多的优化,你需要做的。 – BoltClock 2011-01-28 20:46:12
yes recordData是一个bytearray – Asha 2011-01-28 20:47:54
这对codereview.stackexchange.com来说是一个很好的问题 – 2011-01-28 20:48:06