首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在流上生成XOR校验和的简单方法?

在流上生成XOR校验和的简单方法?
EN

Stack Overflow用户
提问于 2013-01-30 09:45:59
回答 1查看 2.1K关注 0票数 3

在C#中,有没有一种简单的方法可以在MemoryStream (二进制)上生成XOR校验和,不包括前两个字节和最后两个字节?

此外,扩展BinaryWriter并在编写流时执行该操作是否更容易?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-30 09:52:41

您可以使用LINQ获得答案:

代码语言:javascript
复制
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
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14595341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档