Encoding problem hex to asc

Hello,
I think I have an encoding problem on the lines of code below because the value of the “DecimalValue” variable is 65533, whereas it should be 168 for a hex with a value of A8.

Can you help me, or is this a bug?

Thank you.
Sincerely,

<cfset hexChar = "A8" />
<!--- Convertir l'hex en binaire puis obtenir la valeur ASCII --->
<cfset binaryValue = BinaryDecode(hexChar, "hex") />
<cfset decimalValue = Asc(binaryValue) />

<!--- Afficher le résultat --->
<cfoutput>La valeur décimale de #hexChar# est : #decimalValue# - Binary - #BinaryValue#</cfoutput>

OS: Linux (5.4.0-216-generic) 64bit Ubuntu
Java Version: 11.0.7 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.35
Lucee Version: Lucee 6.2.1.122

what are you trying to do with ASC here?

it’s taking the first character from binaryValue and converting it to ascii?

Asc( string=string*, position=number* );

The normal way to convert a hex number o a decimal would be to use

inputBaseN( hexchar, "16");
toNumeric( hexchar, "hex");

Hello,

That’s okay, thank you very much for your contribution.

Sincerely,
Mathieu

1 Like