0

This question already has an answer here:

I'm reading the RFID output and I can print it to the serial monitor as human readable. But what I want is to assign that to a variable. But I'm getting the ASCII. Is there any way to convert it and get to the variable like Serial.write() do.

byte readbackblock[19];

for (int j=0 ; j<16 ; j++)//print the block contents
    {
      Serial.write (readbackblock[j]);
      cardNumber += readbackblock[j];
    }

Serial.print(cardNumber);

Serial output

read block: 1234567890123456

49505152535455565748495051525354

Any help please.

marked as duplicate by Majenko, jfpoilpret, Dat Ha, Mattia, dhimaspw Jan 3 '17 at 1:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What do you mean "assign that to a variable"? It is in a variable already or you wouldn't be able to print it. It looks like the variable is called readbackblock. – Nick Gammon Dec 31 '16 at 7:32
  • I want to convert this ASCII 49505152535455565748495051525354 number to this 1234567890123456. I can do that on the Serial.write(), but what I wan't is to send the output to some other without printing on the Serial. – Vimukthi Saranga Dec 31 '16 at 10:19
  • @Majenko thank you very much, that did the trick :) (Y) – Vimukthi Saranga Dec 31 '16 at 10:25
-1

I don't think it is possible.

The Arduino is 8-bit microcontroller, and can't handle integers larger than 32-bit. The maximum value for a unsigned 32-bit integer is 4294967296. This is a smaller number than your readblock, so it wil never fit.

If you want to do this with smaller numbers, you can use these 2 function:

  • atoi -> convert char array to integer
  • atol -> convert char array to long integer
  • Can't handle is a bit of a long bow to draw. I have a sketch here that calculates 3^160 = 21847450052839212624230656502990235142567050104912751880812823948662932355201 - now that's quite a big number. The issue isn't the size of the number. – Nick Gammon Dec 31 '16 at 8:40
  • The issue isn't how to "assign to a variable". The issue is something else. Perhaps the question could be clarified? – Nick Gammon Dec 31 '16 at 8:41
  • I want to convert this ASCII 49505152535455565748495051525354 number to this 1234567890123456. I can do that on the Serial.write(), but what I wan't is to send the output to some other without printing on the Serial – Vimukthi Saranga Dec 31 '16 at 10:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.