Go Down

Topic: Using XOR for checksums (Read 124 times) previous topic - next topic

Pugwash

I have not found much on the use of XOR on the forums, so I decided to make a short demo sketch with an explanation of how it works with checksums.

The history is, that about 15 years ago I wrote some programs to receive serial data from GPS and AIS receivers for use with an old Mac Book Pro on my sailing boat.

I thought it was going to be complex, how wrong I was.

So I have uploaded a simple guide to how XOR checksums work to my Github website, for anyone who is interested.

Check it out at https://github.com/The-Black-Pig/XOR_checksum

All comments welcome!

lastchancename

I thnk OP meant to post this.
His keyboard may be broken ?
Code: [Select]
// calculates the checksum of any given ASCII string using XOR
// sketch by Steve Clements 2019

char dataString[] = "arduino"; //the string source for the checksum
byte xorTemp;

void setup() {
  Serial.begin(9600);

}

void loop() {
  // print first character ASCII decimal value
  xorTemp = byte(dataString[0]);
  Serial.println(xorTemp);
  
  // process the remaining string characters
  for(int i = 1; i < sizeof(dataString) - 1; i++){
    xorTemp ^= byte(dataString[i]);
    Serial.println(xorTemp);
    delay(250);
    }
  // convert the last XOR result to hexadecimal
  Serial.print("The checksum equals ");Serial.println(xorTemp, HEX);

}
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up