How to convert a string to long int? [closed]
Clash 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.
programming
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
add a comment |Â
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.
programming
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
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
add a comment |Â
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.
programming
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.
programming
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
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
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
add a comment |Â
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
add a comment |Â
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);
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
add a comment |Â
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:
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.
add a comment |Â
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);
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
add a comment |Â
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);
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
add a comment |Â
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);
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);
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
add a comment |Â
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
add a comment |Â
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:
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.
add a comment |Â
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:
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.
add a comment |Â
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:
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.
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.
answered Aug 26 at 9:37
Michel Keijzers
5,63341733
5,63341733
add a comment |Â
add a comment |Â
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