Base Conversions

All flavors welcome.
Forum rules
Be kind.
Post Reply
User avatar
richmond62
Posts: 3896
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Base Conversions

Post by richmond62 »

Supposedly baseConvert can, erm, convert, Hexadecimal number into Decimal ones: but this does not seem to be true:
-
SShot 2024-10-08 at 11.55.57.png
SShot 2024-10-08 at 11.55.57.png (15.2 KiB) Viewed 698 times
-
SShot 2024-10-08 at 11.56.22.png
SShot 2024-10-08 at 11.56.22.png (18.65 KiB) Viewed 698 times
-
SShot 2024-10-08 at 11.58.15.png
SShot 2024-10-08 at 11.58.15.png (23.01 KiB) Viewed 698 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 3896
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Base Conversions

Post by richmond62 »

Another LC-inconsistency:
-
SShot 2024-10-08 at 12.02.32.png
SShot 2024-10-08 at 12.02.32.png (18.1 KiB) Viewed 696 times
-
A Hex number that contains ONLY digits does NOT need double quotes, but a Hex number that contains alphabetics needs double quotes.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 3896
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Base Conversions

Post by richmond62 »

What is interesting is that while that works in the MessageBox,
it does NOT seem to in a button:

Code: Select all

on mouseUp
   put empty into fld "SCL"
   ask "Start of Unicode range in Hexadecimal: "
   put it into HEXK
   put quote before HEXK
   put quote after HEXK
   put baseConvert(HEXK, 16, 10) into KOUNT
The script gets stuck at the baseConvert.
https://richmondmathewson.owlstown.net/
User avatar
tperry2x
Posts: 2475
Joined: Tue Dec 21, 2021 9:10 pm
Location: Somewhere in deepest darkest Norfolk, England
Contact:

Re: Base Conversions

Post by tperry2x »

richmond62 wrote: Tue Oct 08, 2024 9:31 am What is interesting is that while that works in the MessageBox,
it does NOT seem to in a button:

Code: Select all

on mouseUp
   put empty into fld "SCL"
   ask "Start of Unicode range in Hexadecimal: "
   put it into HEXK
   put quote before HEXK
   put quote after HEXK
   put baseConvert(HEXK, 16, 10) into KOUNT
The script gets stuck at the baseConvert.
You could try this. It tries with the quoted and unquoted form, and outputs in the message box:

Code: Select all

on mouseup
   ask "Start of Unicode range in Hexadecimal: "
   put it into hHex
   try
      put baseConvert(hHex, 16, 10) into hCount
   catch e
      if e is not "" then
         put "error while trying unquoted: " & hHex into e
         -- try with quotes
         put QUOTE & hHex & QUOTE into hHex
         try
            put baseConvert(hHex, 16, 10) into hCount
         catch e
            put "error while trying unquoted & quoted approaches: " & hHex into e
         end try
      end if
   end try
   if e is "" then
      put hCount
   else
      put e
   end if
end mouseup
User avatar
OpenXTalkPaul
Posts: 2266
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: Base Conversions

Post by OpenXTalkPaul »

richmond62 wrote: Tue Oct 08, 2024 9:00 am Supposedly baseConvert can, erm, convert, Hexadecimal number into Decimal ones: but this does not seem to be true:
If 'unquoted' how would the script engine know if it's a variable name or a hexadecimal literal? (that's a rhetorical question)
The '0x' (like 0x12AF) I believe according to the docs '0x' is supposed to be recognized by the interpreter as a hex literal value, but I don't think it's ever worked the few times I've tried to use it.

I've never had baseConvert not work though.

At some point I think I've rolled my own routine for Decimal<>Hex
I also acquired a script ( sometime in the late 1980s) that does decimal to binary 'bits' (as a string of '0's and '1's) that is about as fast as a compiled external function, even on a 0.6MHz Motorola 68K CPU :lol: .
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests