How can I convert a character in a string to a number?

98 Views Asked by At

I am currently making a converter for converting hexadecimals into decimal. When I put a character in console, it says

"Argument #1 expected a string. It provided an Integer".

I tried using Char(ToInteger(n)) and Char(ToCode(n)) but it always returns with

"Argument #1 expected a string. It provided an Integer".

Please tell me what is lacking or what is the problem

1

There are 1 best solutions below

0
Costantino Grana On

I guess you want to convert a string containing the hexadecimal representation of a number into an integer. You need to work through your string character by character and for every character use the ToChar() function. The function wants a string of length 1 and converts the single character into its value in the ASCII table. Example:

example

This prints

48
65
97

From here you can work out the other cases.