Now() to Mifare

Thanks for the help with my last problem.

Now I'm trying to write the time to a dataBlock in epoch time. Which functions do I need to research?

Example

unsigned long now = now()

Let's say now= 1500500500

I would like to 'separate' them into 15,00,50,05,00

I will then write them to card in separate buffers, I can do that. Then when I read the card again, I'll get the 15,00,50,05,00.

How do I 'reconnect them back into one 'now' variable?

Thanks again.

15,00,50,05,00

1500500500 = 00 * 10^0 + 05 * 10^2 + 50 * 10^4 + 00 * 10^6 + 15 * 10^8

Not sure what this is or solves for me?

This is the answer to the question

How do I 'reconnect them back into one 'now' variable?

You "split" the long into a few integers, now you want to re-create the long from those integers. This is what I thought you are looking for.
If the 2-digit numbers are strings (but why would you not save them directly as integers?), then convert them, to integers and perform the same calculation.
In any case, why not save the whole long as a long? In other words, why do you need to split?

unsigned long now = now()

Let's say now= 1500500500

I would like to 'separate' them into 15,00,50,05,00

I will then write them to card in separate buffers, I can do that. Then when I read the card again, I'll get the 15,00,50,05,00.

Why not store and retrieve the four bytes of the unsigned long?

why not save the whole long as a long? In other words, why do you need to split?

Because an RFID card stores bytes so you need to split up a number into bytes before you can write them.

Explore a using a union ?
A Tutorial here

eg

union Time_Union {
   unsigned long now;
   uint8_t now_bytes[4];
};

Time_Union miFare_time;

Will look into Darrob.

Sorta like this florinc?

unsigned long now=now();	      //example if now = 1500500500

buffer[10]=now % 10;		      // should be 0
buffer[9]=(now/10) % 10;	      // should be 0
buffer[8]=(now/100) % 10;	      // should be 5
buffer[7]=(now/1000) % 10;	      // should be 0
buffer[6]=(now/10000) % 10;	      // should be 0
buffer[5]=(now/100000) % 10;	      // should be 5
buffer[4]=(now/1000000) % 10;	      // should be 0
buffer[3]=(now/10000000) % 10;        // should be 0
buffer[2]=(now/100000000) % 10;       // should be 5
buffer[1]=(now/1000000000) % 10;      // should be 1

Your latest code splits the long into decimal digits.
If you want bytes, should similarly use 256 instead of 10.
If you want hexadecimals, use 16 instead of 10.

I still don't understand why not save it as a long. Saved as a long, read as a long.

I will try to save to Mifare as a long, but it saves in bytes, longest being 255. That's why I'm trying to break apart.

Pickydesign:
I will try to save to Mifare as a long, but it saves in bytes, longest being 255. That's why I'm trying to break apart.

If you can save up to 255 bytes, there is no issue. an unsigned long integer is only 4 bytes (on an UNO)
If you can only save a single byte at a time, use a union and write each byte of the time longint one byte at a time.

To split a four byte variable into byte use:-

byte1 = variable >> 24;
byte2 = (variable >> 16) & 0xff;
byte3 = (variable >> 8 ) & 0xff;
byte4 = variable & 0xff;

To assemble it again

variable = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;

Figured it out. Used my code above to break up into single digits, write to card as dataBlocks[0-9]

Then read from card and String buffers[0-9] together (backwards)

Then string.toInt and I get the written now() last time card was scanned

Im sure there might be an easier way I will revisit options later. I've been stuck on this for a week and I appreciate the help. On to next problem we go!