Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * decimalToBinary.go
- * Simple algorithm to convert decimal to binary in golang
- *
- * 2019 - Mochamad Syarief Maulana
- */
- package main
- import "fmt"
- var n, input int
- func main() {
- fmt.Scanln(&input)
- n = 1
- for n*2 <= input {
- n = n * 2
- }
- for n >= 1 {
- fmt.Print(input / n)
- input = input % n
- n = n / 2
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement