Well, you can do small chunks of numbers by co-opting the rgb function, as in:
put rgb("A9")
-- rgb( 0, 0, 169 )
The problem is that when you go over one byte, then you get each byte
individually, and of course, it doesn't go over three bytes total
put rgb("F31AA9")
-- rgb( 243, 26, 169 )
So, if you want to build the final number, you have to take each answer and
shift it left (bitwise), in this case by multiplying by 256 for each
position it is, and add it to the total.
In other words:
put (243 * (256 * 256)) + (26 * 256) + 169
-- 15932073
Note that 243 shifts twice, and 26 shifts once and 169 shifts not at all.
The major problem here is that you have an upper limit of 0xFFFFFF, not
quite a 32-bit max, more of a 24-bit max. If you can live with that, I'd
say a easy converter might be:
on hexToDec hexNum
-- Example hex to dec
-- 24-bit max
-- Tab Julius ([EMAIL PROTECTED])
parts =rgb(hexNum)
decNum =parts.red * (256 * 256)
decNum =decNum + (parts.green * 256)
decNum =decNum + parts.blue
return(decNum)
end
put hexToDec("F31AA9")
-- 15932073
And you could put it all in one big line - I just broke the decNum into
three steps to make it easier to follow.
Hope that helps...
- Tab
At 11:43 AM 6/7/02 +0100, [EMAIL PROTECTED] wrote:
>Not being very maths-oriented, I've been trying to decipher some formulae I
>found online which convert hex to decimal numbers, with a view to
>re-writing it in lingo, but my head is hurting already. Even better would
>be if there was some undocumented hexToDec function in lingo that I was
>unaware of. Can anyone help?
>
> Chris
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]