在C#中,有没有一种简单的方法可以在MemoryStream (二进制)上生成XOR校验和,不包括前两个字节和最后两个字节?
此外,扩展BinaryWriter并在编写流时执行该操作是否更容易?
发布于 2013-01-30 09:52:41
您可以使用LINQ获得答案:
var checksum = memStream
.GetBuffer() // Get the underlying byte array
.Skip(1) // Skip the first byte
.Take(memStream.Length-3) // One for the beginning, two more for the end
.Aggregate(0, (p,v) => p ^ v); // XOR the accumulated value and the next bytehttps://stackoverflow.com/questions/14595341
复制相似问题