# How can i write/read an integer to eeprom?

int temp;

how can i write to eeprom the content of temp? what if it has more than 1 digit? for example "123" does the code need to split to 1,2,3 and write to 3 adresses?

123 is less than 255 which is the largest value you can store in a byte. However "123" is a string and takes up four bytes.

yeah mistake i mean 123 not "123"

but what about 654? and what is the syntax to do that? do i need to split it and write 6,5,4 in 3 addresses? and how can i join them?(on reading)

``````int x = 645;
byte hix = highByte (x);
byte lox = lowByte (x);
``````
``````int x = 645;
byte hix = highByte (x);
byte lox = lowByte (x);
``````

thanks for that, a little explain? :-? what value will have the hix and what the lox on this example?

mmm is the split of 645 in 2 bytes?

searching on the internet i saw this elocity = -200 = hex FF38 = [hex FF] [hex 38] =   Radius = 500 = hex 01F4 = [hex 01] [hex F4] =  

so i think i undestand now..

and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom? and how do i know when i read from eeprom if the value have 1 or 2 addreesses? if i read always 2 adresses then if the number i saved was less than 256 i'll get wrong result

and how i merge them? ;)

(hix * 256) + lox

and another question. do i need to check a demical if it is >than 256 to use high/low fuction before i save it to eeprom?

Integers have no decimal point.

and how do i know when i read from eeprom if the value have 1 or 2 addresses?

eeproms only directly write or read to byte addresses, so you always have to write or read two bytes to save or retrieve a integer number no matter what it’s value is.

if i read always 2 addresses then if the number i saved was less than 256 i’ll get wrong result

No you will get correct results (even if <256) if you use AWOL’s formula, x= (hix * 256) + lox;

Lefty

search for eepromwriteanything.

Mowcius