STACK: Is it possible to use student input in hexadecimal or other base N number form?

STACK: Is it possible to use student input in hexadecimal or other base N number form?

by Lukasz Kadlubowski -
Number of replies: 2
Hello,

I'm struggling with creating questions that ask students to perform some basic conversion operations between different numeric representations (binary, octal, decimal, hexadecimal, or base N in general). I would also like to create some questions that ask to perform addition of hex numbers, multiplication of U2 binary numbers etc.

What I found is that it is at least not easy due to the following:
  • printf function is not supported (probably for security reasons)
  • stackintfmt variable only affects how the numbers are displayed, not the input interpretation (?)
  • Maxima textnumformat is overriden by stackintfmt (?)
  • ibase / obase are not working as expected (and are discouraged?)
The topic was discussed in the past, but I have not found any recent update on this. Related topics are:
Since I'm new to STACK it may be that I am doing something wrong and the issue has been resolved as of 2022, but I spent a considerable number of hours trying to figure it out, without success.

So I would like to ask if there is a general method to interpret student input as binary, hexadecimal, etc. and use these in generating prt response? If the answer is positive, are there any exemplary questions available?

Regards,
Luke



Average of ratings: -
In reply to Lukasz Kadlubowski

Re: STACK: Is it possible to use student input in hexadecimal or other base N number form?

by Evgeniy Grishenko -
You can write custom functions to work with number representation and use string variables for input. I used  similar trick to work with cyclic permutations.
Average of ratings: Useful (1)
In reply to Evgeniy Grishenko

Re: STACK: Is it possible to use student input in hexadecimal or other base N number form?

by Lukasz Kadlubowski -

Thank you Evgeniy smile

Some time ago I wrote such functions and was hoping to refactor them soon after. Unfortunately, this won't happen in the near future, so I share current stage of my work. Maybe it will be of use for somebody, but be warned that these were my first steps in Maxima.

The code provides two public functions:

int2string(int, radix) - returns a string with requested representation of int. int is always decimal, string is in requested base. The function accepts radices in the range 2-16

string2uint(string, radix) - returns a list with four elements:

  1. is_empty_string - boolean, true if string is empty
  2. is_num_string - boolean, true if string contains only numerical characters within max base supported: [0-9A-Fa-f] (hexadecimal)
  3. is_in_num_system - boolean, true if string contains only digits that are valid for the claimed radix
  4. uint - unsigned integer (always decimal)
The second function does not support negative numbers and none of them supports fractional numbers, I'd like to improve it in the future.

Attached are *.mac files with the code and the same code in wxMaxima project file (requires STACK libraries loaded).