• 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: Michelle Steiner <email@hidden>
  • Date: Mon, 3 Jan 2005 22:59:43 -0700

On Jan 3, 2005, at 8:59 PM, Bernardo Hoehl wrote:

Has anyone ever written a handler to convert binary to decimal?

Here is one that uses plain vanilla Applescript; it's slower that calling a shell script, though. Most of the code is to validate that the value is actually a binary number.


set inputstring to handleinput()
set calculation to 0
set stringlen to length of inputstring
repeat with counter from 1 to stringlen
set exponent to stringlen - counter
set calculation to calculation + ((item counter of inputstring) as integer) * (2 ^ (exponent))
end repeat


display dialog calculation

on handleinput()
set testset to {"1", "0"}
set goodinput to false
repeat until goodinput
set testresult to text returned of (display dialog "Enter a binary number or click Cancel." default answer "")
repeat with testchar in testresult
if testchar is not in testset then
set goodinput to false
else
set goodinput to true
end if
end repeat
end repeat
return testresult
end handleinput


--
"The past is like a foreign country. They do things differently there." --Leslie Poles Hartley


_______________________________________________
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


  • Follow-Ups:
    • Re: Converting binary to decimal
      • From: HÃ¥vard Graudo <email@hidden>
References: 
 >Converting binary to decimal (From: Bernardo Hoehl <email@hidden>)

  • Prev by Date: Re: Converting binary to decimal
  • Next by Date: Re: Converting binary to decimal
  • Previous by thread: Re: Converting binary to decimal
  • Next by thread: Re: Converting binary to decimal
  • Index(es):
    • Date
    • Thread