Continuing my EEPROM tests, I stored data as ShortInt and Integer (which can be positive or negative). Reading back as the proper type variable yields the respected results. Reading back as bytes, the negative values are in 2s-complement format.
Saving constant values is more interesting. They need to be read back in the appropriate format. If you don't know the size of the value stored, you may get the wrong result.
The conclusions are pretty simple:
¤ You need to leave enough space for the format you are storing.
¤ You need to read the data as the same type it was stored.
¤ If you save constant values, you need to consider how a value of that size would have been stored and read it as the proper type.
No big surprises here, just details to be aware of.
Saving constant values is more interesting. They need to be read back in the appropriate format. If you don't know the size of the value stored, you may get the wrong result.
The conclusions are pretty simple:
¤ You need to leave enough space for the format you are storing.
¤ You need to read the data as the same type it was stored.
¤ If you save constant values, you need to consider how a value of that size would have been stored and read it as the proper type.
No big surprises here, just details to be aware of.
Code:
===========================================================
Part 5 - ShortInt and Integers
EE.30 = Short +42, EE.32 = Short -42, EE.34 = Int +42, EE.36 = Int -42
Read as bytes
Addr29: 255
Addr30: 42
Addr31: 255
Addr32: 214
Addr33: 255
Addr34: 42
Addr35: 0
Addr36: 214
Addr37: 255
Read in format written.
Addr 30: 42
Addr 32: -42
Addr 34: 42
Addr 36: -42
===========================================================
Part 6 - Constants
EE.40 = 42, EE.42 = -42, EE.44 = 747, EE.46 = -747
Read as bytes
Addr39: 255
Addr40: 42
Addr41: 255
Addr42: 214
Addr43: 255
Addr44: 235
Addr45: 2
Addr46: 21
Addr47: 253
EE.40 read in various formats. =42
Addr 40 as byte: 42
Addr 40 as word: 65322
Addr 40 as short int: 42
Addr 40 as int: -214
EE.42 read in various formats. -42
Addr 42 as byte: 214
Addr 42 as word: 65494
Addr 42 as short int: -42
Addr 42 as int: -42
EE.44 read in various formats. =747
Addr 44 as byte: 235
Addr 44 as word: 747
Addr 44 as short int: -21
Addr 44 as int: 747
EE.46 read in various formats. =-747
Addr 46 as byte: 21
Addr 46 as word: 64789
Addr 46 as short int: 21
Addr 46 as int: -747