SHARE
TWEET

Untitled

a guest Sep 17th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top