Re: Converting binary to decimal
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