Hello
I need to turn Hex number to decimal values in survey123 connect for one question?
do we have any formula or work around to achieve this?
Best
Solved! Go to Solution.
You could use the parseInt() javascript function to convert hex numbers to integers.
function hexToInt(hex) {
return parseInt(hex, 16);
}
Then use the survey123 calculation:
pulldata("@javascript", "functions.js", "hexToInt", ${your_hex_field})
While java can do this with less steps, not everyone can use Java in their environment. To do this inside of S123 natively, you can use the attached (at least as a starting point).
input_txt
Your HEX input (only built it for 4 digits, but didn't add a bind::esri:fieldLength).
input_stuff
These calculates isolate the positions of the characters. E.g., substr(${input_txt}, 2, 3) will grab the third character of the string within input_txt. It starts from 0, and reads left to right.
convert_stuff
Will convert the alpha character (A to F) into a decimal number (10 to 15), or return the decimal number (0 to 9) without changing it.
calculate_stuff
multiplies the number by 16^x, where x is the position (This will explain better than me)
output_txt
Your decimal output
S123:
Verification:
Two things:
Is everyone using the form in your organization? If so, you could use a JavaScript function, JS can convert hex to decimal pretty easily
@MobiusSnake Hey unfortunately I don't know JS. 😞
Thanks @abureaux do you know how can I use this calculation in survey123 Calculate field.
You could use the parseInt() javascript function to convert hex numbers to integers.
function hexToInt(hex) {
return parseInt(hex, 16);
}
Then use the survey123 calculation:
pulldata("@javascript", "functions.js", "hexToInt", ${your_hex_field})
While java can do this with less steps, not everyone can use Java in their environment. To do this inside of S123 natively, you can use the attached (at least as a starting point).
input_txt
Your HEX input (only built it for 4 digits, but didn't add a bind::esri:fieldLength).
input_stuff
These calculates isolate the positions of the characters. E.g., substr(${input_txt}, 2, 3) will grab the third character of the string within input_txt. It starts from 0, and reads left to right.
convert_stuff
Will convert the alpha character (A to F) into a decimal number (10 to 15), or return the decimal number (0 to 9) without changing it.
calculate_stuff
multiplies the number by 16^x, where x is the position (This will explain better than me)
output_txt
Your decimal output
S123:
Verification:
Two things: