Re: How short can I make it
Re: How short can I make it
- Subject: Re: How short can I make it
- From: Ron Hunsinger <email@hidden>
- Date: Fri, 14 Oct 2011 18:55:15 -0700
On Oct 14, 2011, at 1:30 PM, Doug McNutt wrote:
> Understanding that limits of Applescript. might forbid it. . .
>
> What I was really thinking is to place the datecode into a 32 bit register with a shift capability into another register. Such things were once called the A and Q registers but now that bytes are stored backwards I donno.
> Part of the problem is that I come from a world of 48 bit doubles and 6 bit bytes with no such thing as lower case. The digits 0-9 were in fact represented by their 6 bit binary equivalents. There were lots of advantages to that. But IBM came along with 9 track tapes and the world wanted ASCII and lower case that came with it. I feel much the same with this OS 9 8500. My 1982 Jeep navigates the highways and my 1957 Piper Apache uses the same runways . . . when I can afford the avgas. Sigh.
And now you're in a world where bits, bytes, words, and registers have no meaning.
In this new world, you have variables, not registers. Variables hold values, not bits or bytes.
You may have to worry about overflow, because the values will have a limited range, but other than that you needn't (and shouldn't) consider whether the value is stored in binary or decimal, or whether it's big-endian or little-endian. Not only are such concerns no longer important, they aren't even meaningful. It's the value that matters, not its representation.
If you wanted to convert to hexadecimal, in the old world you'd shift off the low-order 4 bits in a loop. Nowadays, you'd divide by 16, and trust the compiler to optimize that into a shift if it's reasonable and useful to do so. (AppleScript won't find it useful, but that's an implementation detail. No compiler will find it useful on a decimal machine, like the one I cut my teeth on.) To convert to base 36 or 62, you'd shift by 5.1699250016 or 5.954196308 bits, or get the same effect more simply by dividing by 36 or 62. (Notice that using base 62 only saves you about 15%.)
If you don't want the leading "digit" of the base-36 result to be numeric (because it might then be confused for a number), make the leading digit base 26:
on to_36(x)
set rslt to ""
repeat while x > 25
set rslt to (character (x mod 36 + 1) of "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") & rslt
set x to x div 36
end repeat
return (character (x + 1) of "ABCDEFGHIJKLMNOPQRSTUVWXYZ") & rslt
end to_36
-Ron Hunsinger
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden