Page 1 of 1

Hex-ache

Posted: Wed Aug 20, 2025 6:51 pm
by richmond62
If I do this sort of thing:

Code: Select all

put codePointToNum("Ξ")
I get 926, which is that code point's Unicode address in decimal format . . .

which is a bit of a pain in the bum as I should like it in Hexadecimal (39E) without having to play "silly buggers' with the calculator app (especially when I have about 3,000 of those to cope with) . . .

Is there any way to use codepointToNum to get a Hex number?

This is inaccurate:
-
Screenshot 2025-08-20 at 20.52.56.png
-
insofar is does NOT state that that number is returned in decimal format.

This can be done in JavaScript:

Code: Select all

(945).toString(16); // returns "3b1"
Of course I could use baseConvert, but I was wondering if there was a more direct method.

Re: Hex-ache

Posted: Wed Aug 20, 2025 7:02 pm
by dunbarx
richmond.

Try:

Code: Select all

function charToHex pChar
   return format("%04X",codePointToNum(pChar))
end charToHex
Craig

Re: Hex-ache

Posted: Wed Aug 20, 2025 7:54 pm
by stam
richmond62 wrote:
Wed Aug 20, 2025 6:51 pm
Of course I could use baseConvert, but I was wondering if there was a more direct method.
How is this not a direct method? This is the proper tool in liveCode to do just what you're asking, simply.

For your use case, 1 line:

Code: Select all

get baseConvert(codepointToNum(<char>), 10, 16)

To make it easier, you could wrap this into a stack-level function to simplify coding, eg:

Code: Select all

function hexOfChar pChar
    return baseConvert(codepointToNum(pChar), 10, 16)
end hexOfChar
You can then call this simply with:

Code: Select all

put hexOfChar(<char>) into <whatever>
Attached is a tiny stack that has this in its stack script so can be used anywhere, very simply. The stack script fires on textChanged of the source field.

Re: Hex-ache

Posted: Wed Aug 20, 2025 7:58 pm
by richmond62
Thank you both for your help. 8)