Combine 2 HEX high and low values into 1 integer

With this taken from my LCD's data sheet:
The high and low values are stored separately. If the trigger value is for example 420 then this should be converted to hex (0x1a4). The least significant digits 'a4' are the low value and the most significant '1' is the high value. In this example 1 would be stored in location 18 and 0xa4 would be stored in location 19.

So, I need to be able to read the integer out of EEPROM, but can only read each byte. Like this:
highVal = ui.EEread(18);
lowVal = ui.EEread(19);

How do I put these together to get the integer?

thanks.

Like this:

unsigned int resultVal = (uint16_t)ui.EEread(18) << 8 | ui.EEread(19);

Note, they are not stored in hex. They are stored in binary, the same as everything in the computers memory.

Thanks. I see how that works, but I couldn't quite come up with it myself.

You could also use a union:

union {
  byte myBytes[2];
  uint16_t myInt;
} myUnion;

Then you could place the value 420 in the union:

   myUnion.myInt = 420;

and write them to EEPROM:

  EEPROM.write(18, myUnion.myBytes[0]);
  EEPROM.write(19, myUnion.myBytes[1]);

When you need to retrieve them:

   myUnion.myBytes[0] = EEPROM.read(18);
   myUnion.myBytes[1] = EEPROM.read(19);

   uint16_t value = myUnion.myInt;

As long as you read and write the bytes in the same order, everything should work fine.

Keep in mind that shifts of multiples of 8 are likely optimized to byte moves by the compiler. So the shifts aren't necessarily as bad as they look.

SouthernAtHeart:
Thanks. I see how that works, but I couldn't quite come up with it myself.

The built in EEPROM library now has get() and put() allowing you to read and write types larger than one byte:

int value;

EEPROM.put(18, value);  //Write
EEPROM.get(18, value);  //Read