decomposition long number to byte and recomposition With FRAM I'm using Adafruit FRAM for my little project and have some trouble with recomposition of LONG Variable , right now the recomposition on INTEGER it's fine.
Where I'm wrong with recomposition of LONG number? Thank's for reply :D

#include &lt;SPI.h&gt;
#include "Adafruit_FRAM_SPI.h"

/* Example code for the Adafruit SPI FRAM breakout */
uint8_t FRAM_CS = 10;

//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS);  // use hardware SPI

uint8_t FRAM_SCK = 13;
uint8_t FRAM_MISO = 12;
uint8_t FRAM_MOSI = 11;
//Or use software SPI, any pins!
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);

uint16_t          addr = 0;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif


void setup(void) {
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif

  Serial.begin(9600);

  if (fram.begin()) {
    Serial.println("Found SPI FRAM");
  } else {
    Serial.println("No SPI FRAM found ... check your connections\r\n");
    while (1);
  }
  int interoDaScrivere = 12345;
  long longDaScrivere = 123456789;
  byte a1 = 0;
  byte a2 = 0;
  byte intPt0 = 0;
  byte intPt1 = 0;
  byte longPt1 = 0;
  byte longPt2 = 0;
  byte longPt3 = 0;
  byte longPt4 = 0;
  a1 = byte(interoDaScrivere);        // si scompone l'intero in 2 byte
  a2 = byte( interoDaScrivere &gt;&gt; 8);
  //decomposition Long

  byte b1 = (longDaScrivere);
  byte b2 = (longDaScrivere &gt;&gt; 8);
  byte b3 = (longDaScrivere &gt;&gt; 16);
  byte b4 = (longDaScrivere &gt;&gt; 24);




  //--------------




  // Read the first byte
  uint8_t test = fram.read8(0x0);
  Serial.print("Restarted "); Serial.print(test); Serial.println(" times");

  // Test write ++
  fram.writeEnable(true);
  fram.write8(0x0, test + 1);
  fram.writeEnable(false);
  /*
    fram.writeEnable(true);
    fram.write(0x1, (uint8_t *)"FTW!", 5);
    fram.writeEnable(false);
  */

  fram.writeEnable(true);
  fram.write8(1, a1);
  fram.writeEnable(false);
  fram.writeEnable(true);
  fram.write8(2, a2);
  fram.writeEnable(false);


  fram.writeEnable(true);
  fram.write8(3, b1);
  fram.writeEnable(false);
  fram.writeEnable(true);
  fram.write8(4, b2);
  fram.writeEnable(false);
  fram.writeEnable(true);
  fram.write8(5, b3);
  fram.writeEnable(false);
  fram.writeEnable(true);
  fram.write8(6, b4);
  fram.writeEnable(false);

  //ricomposizione INT
  int interoRicomposto = 0;
  intPt0 = fram.read8(1);
  intPt1 = fram.read8(2);
  //INT RECOMPOSITION 
  interoRicomposto =  ((intPt1 &lt;&lt; 8) | intPt0);
  // ricomposizione LONG
  long longRicomposto = 0;
  longPt1 = fram.read8(3);
  longPt2 = fram.read8(4);
  longPt3 = fram.read8(5);
  longPt4 = fram.read8(6);
 //LONG RECOMPOSITION
  longRicomposto = ((longPt4 &lt;&lt; 0) + (longPt3 &lt;&lt; 8) + (longPt2 &lt;&lt; 16) + (longPt1 &lt;&lt; 24));


  Serial.print("A1 F0 ");
  Serial.print(a1);
  Serial.print(" ");
  Serial.println(intPt0);
  Serial.print("A2  F1 ");
  Serial.print(a2);
  Serial.print(" ");
  Serial.println(intPt1);
  Serial.println(interoRicomposto);



  Serial.print("b1 LongPt1 ");
  Serial.print(b1);
  Serial.print(" ");
  Serial.println(longPt1);
  Serial.print("b2 LongPt2 ");
  Serial.print(b2);
  Serial.print(" ");
  Serial.println(longPt2);
  Serial.print("b3 LongPt3 ");
  Serial.print(b3);
  Serial.print(" ");
  Serial.println(longPt3);;
  Serial.print("b4 LongPt4 ");
  Serial.print(b4);
  Serial.print(" ");
  Serial.println(longPt4);


  Serial.println(longRicomposto);

}

void loop(void) {

}
There is one very obvious error in your code: You are writing the long
number LSB (least significant byte) first: the LSB goes at address 3 of
the FRAM, while the MSB (most significant byte) goes at address 6. You
reconstruct the number with

longRicomposto = ((longPt4 &lt;&lt; 0) + (longPt3 &lt;&lt; 8) + (longPt2 &lt;&lt; 16) + (longPt1 &lt;&lt; 24));


which puts longPt1 (contents of address 3) as the most significant
byte. Thus you are swapping all the bytes around.

Then there is a more subtle error. longPt1 is a byte. According to the
C++ promotion rules, it is implicitly promoted to int before any
arithmetic or logical operation. But since an int is 16-bits, you are
shifting all the bits out when you do longPt1 &lt;&lt; 24. You should cast
the numbers to a 32-bit type before shifting, as follows:



long longRicomposto = (uint32_t) longPt1 &lt;&lt;  0
                    | (uint32_t) longPt2 &lt;&lt;  8
                    | (uint32_t) longPt3 &lt;&lt; 16
                    | (uint32_t) longPt4 &lt;&lt; 24;


Note that I am casting to an unsigned type. Shifting a 1 into the bit
sign of an integer is undefined behavior in C++: the shift must be done
with an unsigned type, then, if needed, cast to a signed type.