27 lines
387 B
Go
27 lines
387 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func itob(i int) string {
|
||
|
var buf [64]byte
|
||
|
j := len(buf)
|
||
|
b := 2
|
||
|
for i > 0 {
|
||
|
j--
|
||
|
buf[j] = "0123456789abcdefghipqrstuvwxyz"[i%b]
|
||
|
i /= b
|
||
|
}
|
||
|
|
||
|
return string(buf[j:])
|
||
|
}
|
||
|
|
||
|
|
||
|
func main() {
|
||
|
var i int
|
||
|
fmt.Print("please enter a number: ")
|
||
|
fmt.Scan(&i)
|
||
|
fmt.Printf("%d as a binary: %s\n", i, itob(i))
|
||
|
}
|