• 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: jj <email@hidden>
  • Date: Tue, 04 Jan 2005 10:11:25 +0100

> At 1:59 AM -0200 04/01/05, Bernardo Hoehl wrote:
>> Has anyone ever written a handler to convert binary to decimal?
>
> Here is one:
>
> ----------------
> write the_binary to f
> set the_decimal to (read f as real)
> ----------------
>
> Emmanuel
>  _____________

Hmmm... If I provide "00000101" as input, it returns 0?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
BinToDec("00000101") --> 1.3980432861154E-76 ("as integer" = 0)

on BinToDec(n) --> credits Emmanuel
    set f to (open for access ("/tmp/tf" as POSIX file) with write
permission)
    set eof of f to 0
    write n to f
    close access f
    read ("/tmp/tf" as POSIX file) as real
end BinToDec
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

btw, this is what I use actually (similar to an already posted routine):

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
BinToDec("00000101") --> 5

on BinToDec(n)
    set dec to 0
    set basex to 0
    repeat with i from (count n) to 1 by -1
        if n's item i is "1" then
            set dec to dec + (2 ^ basex)
        end if
        set basex to basex + 1
    end repeat
    dec
end BinToDec3
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


jj

--
http://www.macscripter.net/
http://www.osaxen.com/


 _______________________________________________
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: Emmanuel <email@hidden>
References: 
 >Re: Converting binary to decimal (From: Emmanuel <email@hidden>)

  • Prev by Date: RE: PDF - pdf.... issue
  • Next by Date: RE: PDF - pdf.... issue
  • Previous by thread: Re: Converting binary to decimal
  • Next by thread: Re: Converting binary to decimal
  • Index(es):
    • Date
    • Thread