Advertisement
ChristophX86

Decimal to Binary

Aug 19th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 0.40 KB | None | 0 0
  1. Func _DecimalToBinary($D, $N=100)
  2.     Local $S = ($D < 0)
  3.     $D = Abs($D)
  4.     Local $F = $D - Int($D)
  5.     $D = Int($D)
  6.     Local $B = ""
  7.     Do
  8.         $B = Mod($D, 2) & $B
  9.         $D = Int($D / 2)
  10.     Until $D = 0
  11.     Local $i
  12.     If ($F > 0) Then
  13.         $B &= "."
  14.         For $i = 1 To $N
  15.             $F *= 2
  16.             $B &= Int($F)
  17.             $F -= Int($F)
  18.             If ($F = 0) Then ExitLoop
  19.         Next
  20.     EndIf
  21.     If $S Then
  22.         Return "-" & $B
  23.     EndIf
  24.     Return $B
  25. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement