Hex To Decimal Conversion Issues

I'm having some issues trying to do this conversion. Pasted below is a test code segment where I'm only trying to convert hex letters back into the appropriate decimals and output the number array. Once this is working fine, I'll go back and do the 16^ multiplications. Any help would be greatly appreicated!

The math blocks include conversion blocks.


Thanks ABG, I will keep that for future reference. I should have clarified earlier that this was part of a class assignment. I'm not sure that the shortcut conversion would have been permissible. The functionality I was trying to achieve was to take the user entered hex number, reverse it, and then check the number for hex letters and perform the appropriate conversion/replacement. If no hex letters were present, then the original user entered number remains the same. The max possible length is 16 bits. For each index place the test program sums the values into global sum, which is returned as the output text. Once this is working properly, I will add in the 16* multiplications to do the final correct conversion.

I'm pretty sure you know this, but you can reverse anything in a jiffy with this simple block:

1 Like

Correct. That's included in the initialization of local variable Num, which begins right after the start of the btn_HexLettersToNum.Click handler block

1 Like

Another code:

Hexadecimal2.aia (2.8 KB)



Thanks. This is much more concise than what I came up with. I'm still looking over my code to see where the issue is. I think the trouble is coming from not having split the text as you did. Copied below is the complete Hex to Decimal block that still has issues.

In your code, you enter Num = 3F9C and replace it with Num = 315912
You don't get the digit separation: 3,15,9,12

1 Like

I added a split operation to the code, shown below. When I test on hex 7DE, I get the error listed below:

The operation * cannot accept the arguments: , ["["], [1]

In that code you convert the variable Num into a list.

Set a LabelX below the Num (split) block and observe LabelX.Text = Num


I'm still getting the same " The operation * cannot accept the arguments: , ["["], [1] " error with the suggested modification, shown below.

Your problem stems from not having learned the basics of manipulating lists and list items.
When you used the text split block it returned a list.
See the article How to Work With Lists in

You are missing the block
for each num in (split text at "")

1 Like

1 Like

I'm reworking the block per your comments. In the " List Blocks On App Inventor" article, it didn't seem clear if a string with no spaces, such as "7DE" could be split into a list of individual characters (i.e. [7DE]). What I've historically wound up with is ["7DE"], a list with a single string entry. It doesn't seem like there is a way to specify that the string be split at the individual character level, rather than at a whitespace or other delimiter entry. Is this the case? If so, I have additional revisions to do. Thanks again.

If you give an empty text block (no space, length 0) as the place to split, AI2 will split between every character and the next. There will be an extra empty item at position 1 of the resulting list, that you should remove.

P.S. That's exactly what Juan Antonio just did for you.

1 Like

Excellent! Thanks ABG, that should cut down on the rework on my side.

Thanks to ABG's and Juan_Antonio's input, I'm closer to the correct solution, but still having access issues. I'm testing the access with integers rather than with current index and "length of" variables. If I use a hex input of "7DE" and set the "to" value to 4 in the "for each" block, I get the error message below, which is no surprise as the length of the hexEntry array only 3. The good news is that now the proper hex to decimal conversions are taking place. If I change the "to" value to 3, I get the answer "[]" returned in the lbl_DecimalNumberOutput label. I also get the same answer if I change "to" to "length of" global hexEntry.

Select list item: Attempt to get item number 4 of a list of length 3: ["7", 13, 14]


1 Like

I made the additions, as shown below. If I input "7DE", the answer im getting back in "[]"

What do you get in decimalSum?

1 Like