home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / CLImax 1.0 / AppleScript and CLImax / Advanced AppleScript / Handlers to try / binary / binary.rsrc / TEXT_256.txt < prev   
Encoding:
Text File  |  1996-06-13  |  472 b   |  24 lines

  1. on binary(num)
  2.  if (num<0) then return "Sorry, don't do negative numbers."
  3.  
  4.  set power to 0
  5.  set factor to 1
  6.  repeat while (factor*2) <= num
  7.   set power to power + 1
  8.   set factor to factor * 2
  9.  end repeat
  10.  
  11.  set bstring to ""
  12.  repeat while power >= 0
  13.   if (num >= factor)
  14.    set bstring to bstring & "1"
  15.    set num to num - factor
  16.   else
  17.    set bstring to bstring & "0"
  18.   end if
  19.   set power to power - 1
  20.   set factor to factor / 2
  21.  end repeat
  22.  
  23.  return bstring
  24. end binary