Convert bytes from EEPROM to a integer?

Hi..

Is it possible to convert the bytes from the EEPROM to a integer?

Any Idea? Tks

    byte vrecupera_dados_eeprom[6];
    int vmynumber;

    vrecupera_dados_eeprom[1] = EEPROM.read(20);
    vrecupera_dados_eeprom[2] = EEPROM.read(21);

int myInt = ( int(EEPROM.read(20)) << 8 ) | EEPROM.read(21);

union {
   byte myArray[2];
   int val;
} myUnion;

// ...more code...
myUnion.myArray[0] = EEPROM.read(0);
myUnion.myArray[1] = EEPROM.read(1);
int number = myUnion.val;

The code assumes that the EEPROM data is already in place. If you use the union to put the data into EEPROM, the code fragment above will read it back correctly and you don't have to worry about the byte order (the endian problem) of the data.

Try eeprom_read_word function.

Hi Folks… Tank you very much for the help!

But I ave found a great function what works quite well…
I ave tested and worked

It can be changed to int, long etc…

float readFloat(unsigned int addr)
{
	union
	{
		byte b[4];
		float f;
	} data;
	for (int i = 0; i < 4; i++)
	{
		data.b[i] = EEPROM.read(addr + i);
	}
	return data.f;
}
void writeFloat(unsigned int addr, float x)
{
	union
	{
		byte b[4];
		float f;
	} data;
	data.f = x;
	for (int i = 0; i < 4; i++)
	{
		EEPROM.write(addr + i, data.b[i]);
	}
}