HOW TO COMPARE 2 HEX VALUES STORE IN THE EEPROM

hey guys,

So i stored Hex values in 4 bytes into the eeprom and i am trying to compare the 2 hex values here is my code

#include <EEPROM.h>


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  Serial.println();
  for (int i = 2; i < 6; i++) {  //
int a=EEPROM.read(i);
    Serial.println(a,HEX);
      
  }
  for (int i = 6; i < 10; i++) {  //

int v=EEPROM.read(i);
    Serial.print(v,HEX);
      
  }

  if(a != v){

Serial.print(1);
}


}

void loop() {
  // put your main code here, to run repeatedly:

}

And the error im getting is

sketch_mar15a:22: error: 'a' was not declared in this scope

   if(a != v){

      ^

sketch_mar15a:22: error: 'v' was not declared in this scope

   if(a != v){

           ^

exit status 1
'a' was not declared in this scope

You’re variables are local to the for loop and not known outside it

#include <EEPROM.h>


void setup() {
  // put your setup code here, to run once:

  int a;
  int v;

  Serial.begin(9600);

  Serial.println();
  for (int i = 2; i < 6; i++) {  //
    a = EEPROM.read(i);
    Serial.println(a,HEX);
     
  }
  for (int i = 6; i < 10; i++) {  //

    v = EEPROM.read(i);
    Serial.print(v,HEX);
     
  }

  if(a != v){

Serial.print(1);
}


}

void loop() {
  // put your main code here, to run repeatedly:

}

The assigning of the value to an int is also not correct; your for loop will repeat and at the end only the last value is stored in a or v.

A better approach (based on your code) will be

  bool result = true;

  for (int i = 0; i < 4; i++) {

    int a = EEPROM.read(i + 2);
    Serial.println(a, HEX);
    int v = EEPROM.read(i + 6);
    Serial.print(v, HEX);

    if (a != v)
    {
      // indicate no match
      result = false;
    }
  }

  if(result == false)
  {
    Serial.print(1);
  }