• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How short can I make it
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How short can I make it


  • Subject: Re: How short can I make it
  • From: Paul Abney <email@hidden>
  • Date: Fri, 14 Oct 2011 08:45:51 -0500

I want to thank everyone that responded. I believe I now have a working plan. I will take the number of seconds from a known date (01.01.11) and convert that to base 36, that should do me just fine. Thanks again
Paul


On Oct 13, 2011, at 5:37 PM, Mark J. Reed wrote:

On Thu, Oct 13, 2011 at 6:04 PM, Stan Cleveland <email@hidden> wrote:
On Oct 13, 2011, at 10:01 AM, Mark J. Reed wrote:

9 digits?  Not in decimal - epoch time broke 10 digits in 2001. As I type this it's 1,318,524,834.  That's 8 digits in hexadecimal.  Or 6 digits in base 36 (0,1,2,3,4,5,6,7,8,9,a,b,c,d,...,z)...

Hi Mark, 

Base 36? Very interesting. Do you have AS routines to share for doing conversions between decimal and base 36 and back again? Or even better, between any two bases in the range of, say, 2 to 36?

Stan C.

These should do the trick:

-- convert number into a string representation in the given base
on toString from aNumber by aRadix
  if aRadix < 2 or aRadix > 36 then
    error "unsupported radix " + (aRadix as text)
  end if
  set resultString to ""
  repeat while aNumber > 0
    set digit to (aNumber mod aRadix)
    if digit > 10 then
      set digit to character id (digit - 10 + (id of "A"))
    end
    set resultString to (digit as text) & resultString
    set aNumber to aNumber div aRadix as integer
  end repeat
  return resultString
end

-- parse a string representing a number in the given base
on toNumber from aString by aRadix
  if aRadix < 2 or aRadix > 36 then
    error "unsupported radix " + (aRadix as text)
  end if
  set resultNum to 0
  repeat with aDigit in characters of aString
    set charCode to id of aDigit
    if charCode >= id of "0" and charCode <= id of "9" then
      set digitValue to aDigit as integer
    else if charCode >= id of "a" and charCode <= id of "z" then
      set digitValue to charCode - (id of "a") + 10
    else if charCode >= id of "A" and charCode <= id of "Z" then
      set digitValue to charCode - (id of "A") + 10
    end
    if digitValue >= aRadix then
      error "Digit '" + aDigit + "' out of range for base " + aRadix
    end
    set resultNum to resultNum * aRadix + digitValue
  end
  return resultNum
end

toString from 1318544445 by 36
toNumber from "LT0ZEL" by 36


-- 
Mark J. Reed <email@hidden>

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
References: 
 >How short can I make it (From: Paul Abney <email@hidden>)
 >Re: How short can I make it (From: David Ferrington <email@hidden>)
 >Re: How short can I make it (From: "Mark J. Reed" <email@hidden>)
 >Re: How short can I make it (From: Stan Cleveland <email@hidden>)
 >Re: How short can I make it (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: INDESIGN: Coercing a String to a Constant
  • Next by Date: Re: How short can I make it
  • Previous by thread: Re: How short can I make it
  • Next by thread: Re: How short can I make it
  • Index(es):
    • Date
    • Thread