• 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: Converting binary to decimal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting binary to decimal


  • Subject: Re: Converting binary to decimal
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 5 Jan 2005 11:11:01 +0000

Michelle Steiner wrote on Tue, 4 Jan 2005 18:18:26 -0700:

>On Jan 4, 2005, at 6:07 PM, Nigel Garvey wrote:
>
>>> Here is one that uses plain vanilla Applescript; it's slower that
>>> calling a shell script, though.
>>
>> Not on my machine (G3 400 PowerBook, Jaguar, 12-digit input). 500
>> iterations of the conversion part of your code take 0.6 seconds
>> (Joshua's
>> about the same), whereas 500 iterations of Gnarlodious's shell script
>> take 15 seconds. j
>
>That was my ignorance of unix talking; it assumed that anything arcane
>and shorter would be faster.  Silly me. <g>

;-)

Sorry about a couple of errors that crept into the script I posted last
night. Here's what I meant:

  on binToNum from bin given sign:sign
    try
      script o
        property binChars : bin's characters
      end script
    on error
      error "binToNum: Input is not a string."
    end try
    set num to 0
    considering case
      if (sign) and (bin begins with "1") then set num to -1
      repeat with i from 1 to (count bin)
        set b to item i of o's binChars
        if (b is in "10") then
          set num to num * 2 + b
        else
          error "binToNum: Invalid character(s) in input string."
        end if
      end repeat
    end considering
    return num
  end binToNum

  binToNum from "111111111111" without sign


NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Newbie: Activating Scripting Additions
  • Next by Date: Netter's Dinner @ Macworld SF
  • Previous by thread: Re: Converting binary to decimal
  • Next by thread: Re: Converting binary to decimal
  • Index(es):
    • Date
    • Thread