PaulRB:
We don't want to waste our time or your time fixing code if later you realise what you described is not what you really need. So please tell us what your project is and why you need to store the data this way. What will happen to the data after? What kind of Arduino are you using (because using String is a bad idea on Arduino like Uno, Nano etc).
my project is to write a word (that come from serial monitor ) to a tag using rfid RC522. my arduino is mega.
to write a message on a tag, we should first convert the messge to a hexcode. then we should write that hex in a block of tag In hex code.
pls see these videos.
first video : https://www.youtube.com/watch?v=IlEWzpO2aFI ,
second video: https://www.youtube.com/watch?v=uihjXyMuqMY
now i need to get a word from serial.monitor. then i should convert it to a hex code in the form of a array to access each number of it (for example word "hadi" then convert to hex code = 68 61 64 69 and then save it in a array like array message [15] ={6,8,6,1,6,4,6,9,20,20,20,20,20,20,20,20}). then i should write the array on the block.
the structure of a tag has 16 sector and 64 blocks that each block (in except some blocks ) can store 2 byte date in the form of hexcode. (pls see the videos i pointed ).
if i want for example write "hadi" word to a tag, i should convert it to hex code (= 68 61 64 69 )
then i should write that code on rfid tag( into block bytes (using the first video) ) .
byte sector = 1;
byte blockAddr = 4;
byte dataBlock[] = { // NEW DATA to Write
message [0], message [1], message [2] message [3], message [4] message [5], message [6] message [7], // 1, 2, 3, 4, in this line we save hadi word in hex code
0xFF, 0xFF, 0xFF, 0xFF, // 5, 6, 7, 8,
0xFF, 0xFF, 0xFF, 0xFF, // 9, 10, 255, 12,
0xFF, 0xFF, 0xFF, 0xFF // 13, 14, 15, 16
so i should first get a word from serial monitor.
then i should convert it to hex number and store it in an array.
then i should write it to tag using first video program.