Jump to content



Photo

Converting decimal numbers to another base


  • Please log in to reply
No replies to this topic

#1 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 23 April 2009 - 01:28 PM

Could be used to convert to binary (for example). Also allows padding of the result.

ConsoleWrite(_ToBase(15, 2, 8) & @CRLF) ConsoleWrite(_ToBase(257, 3) & @CRLF) ConsoleWrite(_ToBase(255, 4) & @CRLF) ConsoleWrite(_ToBase(932, 8) & @CRLF) ConsoleWrite(_ToBase(65535, 16, 8) & @CRLF) Exit Func _ToBase($iNumber, $iBase, $iPad = 1)     Local $sRet = "", $iDigit     Do         $iDigit = Mod($iNumber, $iBase)         If $iDigit < 10 Then             $sRet = String($iDigit) & $sRet         Else             $sRet = Chr(55 + $iDigit) & $sRet         EndIf         $iNumber = Int($iNumber / $iBase)     Until ($iNumber = 0) And (StringLen($sRet) >= $iPad)     Return $sRet EndFunc


WBD








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users