Hex To Decimal Conversion Issues

Juan,

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

2 Likes

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]

91fb7ffdc1879145631ed20924edea2d1db5dcb0_2_584x499

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

I corrected some other errors and now have a single integer returned as the result, however for 7DE the integer returned is 3799 rather than the correct answer, 2014.

Convert
ED7 = 3799

2 Likes

Listed below is the final working code. I needed to do the list reversal at the beginning, which should have been extremely obvious in the first place (but wasn't). Thank you Juan_Antonio and ABG for guiding me in the right direction

Now that you've got yours working, I can show you a recursive solution ...

caboose shorten digit_value
math.aia (31.1 KB)

1 Like

Very cool. I'm not sure why the call blocks auto-populated in the procedures drawer don't have the "call" label on them, nor why I don't have the "do it" option to test.

Are you Connected to the Companion?