I am doing some testing with my WL-134 RFID reader.
The RFID reader output is HEX. And i would like to "convert" the string to base 10 before processing the tag data further.
Example from manual:
Module output:
02 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 07 F8 03
Equal ASCII:171A9253A34830010000000000a
We can find card nuber is 171A9253A3,country number is 483 (LSB First)
We can translate these number to Dec format,card number equal: 250000023921 ,
Country number equal 900
I have found several topics regarding HEX to base 10. But it seems that it wont work with my HEX string as the product is always 12 digits as base 10. And the Arduino is only showing me the greatest number "2147483647" (10 digits).
Code I have used for testing is:
long decimal_answer = strtoul("3FC93A2346", NULL, 16);
Serial.print (decimal_answer);
And it seems for me that the result in base 10 is ambigious therefore printing: 2147483647 instead of 273958970182
HEX conversion is OK when using HEX product less than or equal to "2147483647" (10 digits).
Do anyone have some tip here for how to work around this issue with a conversion of these "big" HEX - > DEC conversion?
Hmm, didnt think about that..
The value I am trying to store is when testing is: 273958970182 , more than maximum for unsigned long. Would it be possible to do the conversion and store the result splited in 2? As the first 7 digits is my farmer ID and the last 5 digits is unique animal ID for each tag?
The hex string is not a numerical value, it's just a label, like "drawer 52", which may or may not be the 52nd drawer, treat it as a textual label, not as a numerical value that can be added, subtracted or multiplied by.
aarg:
What is the specific reason why the farmer/animal ID number must be stored in a single value?
If it is possible to store them in 2 variables separated that would be nice. But I don`t find a way to do that... And storing them in one single value doesent work as the number is to big...
edgemoron:
The hex string is not a numerical value, it's just a label, like "drawer 52", which may or may not be the 52nd drawer, treat it as a textual label, not as a numerical value that can be added, subtracted or multiplied by.
The text written on the tag does not necessarily reflect the text read from the tag. Why do you think it is necessary to convert the text read from the tag to a number?
When you can answer that question, we can discuss how to do it, if it is reasonable to do it.
Obviously, if the text always contains 12 characters, and the characters are always digits (hex or decimal), then you could convert the first 6 characters to a number, and then convert the 2nd 6 characters to a number.
But why? Comparing one string to another is going to be conceptually clearer than comparing 4 numbers.
The text written on the tag does reflect the text read from the tag.
If I convert the HEX string: 3FC93A2346 to decimal using browser online converter i get the decimal number: 273958970182. The first 7 digits represents my "farmer ID" and the last 5 digits represent the unique animal tag for these tags.
The plan is to send each tags data to a server`s database. So the conversion to base 10 could off course be done on the server side. But i prefer to do the conversion on the arduino itself if that is possible. The final product of the HEX string in DEC would always be 12 characters.
Attached is the manual for the reader I am testing. It is the "Card Number" I am interested in converted to decimal.
'3' --> 3
0 * 16 + 3 = 3
'F' --> 5 + 10 = 15
3 * 16 + 15 = 63
and so on.
Thank you Paul... How do i use this conversion? And I am not sure if I agree/understand your "example" in the end... Shouldn't`t it be:
(3x 16^9) + (15x 16^8) + (12x 16^7) .....etc
Create a function to do the conversion. The function takes a char * (a pointer to the string to convert) and returns an unsigned long long.
Call the function wherever you have a string to convert to a numeric value.
Shouldn't`t it be:
No.
The first digit is a '3', with a value of 3. The value so far is 3.
The next digit is processed. Its a 'F', with a value of 15. 3 * 16 is 48. 48 + 15 is 63.
Repeat for each digit...
Work it out for yourself. Or, write a simple sketch to call the function with the string I showed, and print the result. I don't have an Arduino with me, or I'd show the intermediate values and the result.
Yup, for what ever reason the Serial.print() method does like 'unsigned long long' or 'uint64_t'. Paul's 'sprintf()' idea works. Or, you could split it apart:
Did you get anywhere with this ? I have the same chip and would love to hear of your success or problems
@
sindrevr:
Hi,
I am doing some testing with my WL-134 RFID reader.
The RFID reader output is HEX. And i would like to "convert" the string to base 10 before processing the tag data further.
Example from manual:
Module output:
02 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 07 F8 03
Equal ASCII:171A9253A34830010000000000
We can find card nuber is 171A9253A3,country number is 483 (LSB First)
We can translate these number to Dec format,card number equal: 250000023921 ,
Country number equal 900
I have found several topics regarding HEX to base 10. But it seems that it wont work with my HEX string as the product is always 12 digits as base 10. And the Arduino is only showing me the greatest number "2147483647" (10 digits).
Code I have used for testing is:
long decimal_answer = strtoul("3FC93A2346", NULL, 16);
Serial.print (decimal_answer);
And it seems for me that the result in base 10 is ambigious therefore printing: 2147483647 instead of 273958970182
HEX conversion is OK when using HEX product less than or equal to "2147483647" (10 digits).
Do anyone have some tip here for how to work around this issue with a conversion of these "big" HEX - > DEC conversion?