How to convert a string to long int? [closed]

How to convert a string to long int? [closed]



I'm new to Arduino and my first project is an RFID reader. since I need a lot of known tags list , i have a problem with not enough memory. for that reason I want to convert strings like : "426d9244", "1265dd39"... to a long int. I know it's been asked but as a new programer I find it hard to understand. an example would be very appreciated also.



This question appears to be off-topic. The users who voted to close gave this specific reason:





You could use the atol() function. However, I think that is not your problem. Perhaps you have blocks of code that is repeated a few times. Do you use the Serial.println in combination with the F() macro?
– Jot
Aug 26 at 9:37





2 Answers
2



If all those are known tags, you can put them in the source code as
32 bit integers. No
need to convert. Or rather, let the compiler do the conversion:


const uint32_t ID_num[ARRAYSIZE] PROGMEM =
Oxbcc0f1c3, Ox821a7d39, Ox4924887c, ...
;



When you read a tag number in hex, in order to compare it with the known
tags, you convert it to the same type using strtoul() from
avr-libc:


strtoul()


uint32_t tag_id = strtoul(tag_string, NULL, 10);





Actualy , it did the compare without even converting the tag_id... , it works perfect now, HOGE thanks!!!
– rafi shoval
Aug 26 at 10:14






Please "accept" the answer to show that it helped you. Thanks!
– Nick Gammon
Aug 26 at 23:23



It's a bit unclear what you want to do with the 'd'or 'dd'in between.



You can check some functions:



strtok: which can split a string based on delimiters (in your case probably 'd'). Than you get an array of strings (e.g. for the first: "426", "9244".



For each string ("426" and "9244") you use function atol to convert it into a long integer.

Popular posts from this blog

PHP code is not being executed, instead code shows on the page

Administrative divisions of China

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼