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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












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.







share|improve this question














closed as off-topic by Juraj, sempaiscuba, Greenonline, VE7JRO, per1234 Aug 27 at 0:30


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


  • "This question does not appear to be about Arduino, within the scope defined in the help center." – sempaiscuba, Greenonline, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    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















up vote
2
down vote

favorite












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.







share|improve this question














closed as off-topic by Juraj, sempaiscuba, Greenonline, VE7JRO, per1234 Aug 27 at 0:30


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


  • "This question does not appear to be about Arduino, within the scope defined in the help center." – sempaiscuba, Greenonline, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    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













up vote
2
down vote

favorite









up vote
2
down vote

favorite











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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








edited Aug 26 at 9:54

























asked Aug 26 at 9:05









rafi shoval

112




112




closed as off-topic by Juraj, sempaiscuba, Greenonline, VE7JRO, per1234 Aug 27 at 0:30


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


  • "This question does not appear to be about Arduino, within the scope defined in the help center." – sempaiscuba, Greenonline, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Juraj, sempaiscuba, Greenonline, VE7JRO, per1234 Aug 27 at 0:30


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


  • "This question does not appear to be about Arduino, within the scope defined in the help center." – sempaiscuba, Greenonline, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 1




    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













  • 1




    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








1




1




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





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






active

oldest

votes

















up vote
2
down vote













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:



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





share|improve this answer




















  • 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

















up vote
1
down vote













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



You can check some functions:



  1. 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".


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






share|improve this answer



























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    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:



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





    share|improve this answer




















    • 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














    up vote
    2
    down vote













    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:



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





    share|improve this answer




















    • 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












    up vote
    2
    down vote










    up vote
    2
    down vote









    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:



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





    share|improve this answer












    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:



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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 26 at 9:53









    Edgar Bonet

    21.8k22343




    21.8k22343











    • 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
















    • 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















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





    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




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










    up vote
    1
    down vote













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



    You can check some functions:



    1. 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".


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






    share|improve this answer
























      up vote
      1
      down vote













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



      You can check some functions:



      1. 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".


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






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









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



        You can check some functions:



        1. 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".


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






        share|improve this answer












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



        You can check some functions:



        1. 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".


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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 26 at 9:37









        Michel Keijzers

        5,63341733




        5,63341733












            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery