C# では、最初と最後の 2 バイトを除いて、MemoryStream (バイナリ) で XOR チェックサムを生成する簡単な方法はありますか?
また、BinaryWriter を拡張し、Stream が書き込まれるときにそれを行う方が簡単ですか?
C# では、最初と最後の 2 バイトを除いて、MemoryStream (バイナリ) で XOR チェックサムを生成する簡単な方法はありますか?
また、BinaryWriter を拡張し、Stream が書き込まれるときにそれを行う方が簡単ですか?
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 byte