c# - How to add multiple bytes and get a byte array? -
given byte array
byte[] somebytes = { 0xff, 0xfe, 0xfe, 0xff, 0x11, 0x00 ,0x00 ,0x00 ,0x00}
what's best add bytes? manually adding of bytes hand hex numbers yield 40b on above example preferably i'd end like:
byte[] bytesum = { 0x04, 0x0b }
actually, need 0x0b part (used checksum). checksum calculated 0x0b xor 0x55 (which yields 0x5e) in case.
i understand isn't normal addition of bytes, how checksum calculated.
manually looping through byte array , adding them results in integer sum.
what's concise way of doing this?
erm,
byte checksum; foreach (var b in somebytes) { checksum = (byte)((checksum + b) & 0xff); }
Comments
Post a Comment