Writing long numbers to EEPROM

Hi guys.
Can anyone explain how to write longer numbers to eeprom. I know how to write/read from here.
And I know that I can write to one bit just numbers to 254.
But I need write for example 8-digit number.
It would be best to write one digit to one bit. I could write them one after another. But then I dont know how to combine them to make one number.
How to split such values into multiple bits?

I’d use a pointer for void type to access the multi-byte number one byte at a time. This works for both disassembly while storing to EEPROM and reassembly while reading from EEPROM. Just do them both in the same order.

Arduino Playground - EEPROMex perhaps?

Even easier.

The current EEPROM.h library packaged with the ide now supports the writing and reading of "anything" with EEPROM.put() and EEPROM.get(). Take a look at the examples.

long EEPROMReadlong(long address) {
  long four = EEPROM.read(address);
  long three = EEPROM.read(address + 1);
  long two = EEPROM.read(address + 2);
  long one = EEPROM.read(address + 3);
  
  return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}

void EEPROMWritelong(int address, long value) {
  byte four = (value & 0xFF);
  byte three = ((value >> 8) & 0xFF);
  byte two = ((value >> 16) & 0xFF);
  byte one = ((value >> 24) & 0xFF);
  
  EEPROM.write(address, four);
  EEPROM.write(address + 1, three);
  EEPROM.write(address + 2, two);
  EEPROM.write(address + 3, one);
}

See File > Examples > EEPROM > eeprom_put and File > Examples > EEPROM > eeprom_get

jmanatee:
long EEPROMReadlong(long address) {
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);

return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}

void EEPROMWritelong(int address, long value) {
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);

EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}

@jmanatee please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (for example the smiley faces in your code), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor.

try this out:

//EEPROMAnything.h

#include <EEPROM.h>
#include <Arduino.h>  // for type definitions

template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
	  EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
	  *p++ = EEPROM.read(ee++);
    return i;
}

I like sending structures to and from EEPROM
Example:

struct config_t {
  double Setpoint;
  double consKp;
  double consKi;
  double consKd;
  int MinPower;
  byte Saved;
} configuration;

void EEPROMLoad() {
  EEPROM_readAnything(0, configuration);
  if (configuration.Saved != 111)return;
  SPZero = configuration.Setpoint;
  consKp = configuration.consKp;
  consKi = configuration.consKi;
  consKd = configuration.consKd;
  MinPower = configuration.MinPower;
  // Setpoint = 0.00;
}

void EEPROMSave() {
  configuration.Setpoint = SPZero;
  configuration.consKp = consKp;
  configuration.consKi = consKi;
  configuration.consKd = consKd;
  configuration.MinPower = MinPower;
  configuration.Saved = 111;
  EEPROM_writeAnything(0, configuration);

}

pert:
See File > Examples > EEPROM > eeprom_put and File > Examples > EEPROM > eeprom_get
@jmanatee please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (for example the smiley faces in your code), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor.

I did, I forgot when I first posted but immediately went back to edit it but it makes me wait like 5 minutes before I can post again