I'm trying to store a state in my data logger. I can read/write fine to SD, but I can't wrap my head around reading/writing a
long value correctly - I've build it down to converting it to char array and back.
My best try so far has been
long temp = 1418172669L; unsigned char buf; buf = temp & 0xFF; buf = (temp >> 8) & 0xFF; buf = (temp >> 16) & 0xFF; buf = (temp >> 24) & 0xFF; long l = buf | (buf << 8) | (buf << 16) | (buf << 24);
l is very different from
temp - currently the output is
-26371. Am I making an obvious mistake?