Created
September 5, 2014 03:46
-
-
Save oskwazir/4badfee2f460e8f3027a to your computer and use it in GitHub Desktop.
Convert positive integer to binary form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func toBinaryString(number:Int){ | |
var s = "" | |
for var n = number; n > 0 ; n = n / 2 { | |
s = ("\(n % 2)") + s; | |
} | |
println("\(s)") | |
} | |
toBinaryString(125) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment