Hex To Decimal Conversion Issues

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?

Capture
For the value procedures (nipple on the left), their name identifies them in expressions that invoke their vales.
For non-value procedures (no nipple), a call verb is needed and provided.

Another code for bases from 2 to 16, changing the base variable.

2 Likes

I connected to the emulator and got the correct result, though "call" still does not appear

It's time for you to read Chapter 21 of the free book
http://www.appinventor.org/bookChapters/chapter21.pdf
from
http://www.appinventor.org/book2
from

Everything I gave you was a function, like sin() or cos() or max(), which typically don't use the verb CALL in their definition or their invocation.

CALL would be used in a subroutine, like
Call Start_World_War_III
but not in the definition of the subroutine

  • Target Missiles
  • Launch Missiles
  • enter bunker
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.