Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. /*
  2. * decimalToBinary.go
  3. * Simple algorithm to convert decimal to binary in golang
  4. *
  5. * 2019 - Mochamad Syarief Maulana
  6. */
  7.  
  8. package main
  9.  
  10. import "fmt"
  11.  
  12. var n, input int
  13.  
  14. func main() {
  15. fmt.Scanln(&input)
  16.  
  17. n = 1
  18.  
  19. for n*2 <= input {
  20. n = n * 2
  21. }
  22.  
  23. for n >= 1 {
  24. fmt.Print(input / n)
  25. input = input % n
  26. n = n / 2
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement