Home:ALL Converter>Convert Arduino checksum-function to C#

Convert Arduino checksum-function to C#

Ask Time:2015-07-06T20:54:51         Author:Hedge

Json Formatter

I've got this Arduino-checksum function I'd like to use in C# to check the validity of the data I received:

chars in Arduino are 1 byte long, ints take two bytes, the corresponding data-type in C# is short

char Send::calcChecksum(const char* const packet, const int packetLength) {
    int i = 0;
    char checksum = 0;
    while(i < packetLength) {
        checksum ^= packet[i++];
    }
    return checksum;
}

How would I write this function in C# ? I'm especially confused what the ^= operator does.

Author:Hedge,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31246457/convert-arduino-checksum-function-to-c-sharp
yy