/* * Take two numbers from the command line and print the fist one * in the base given by the second. */ package main import ( "fmt" "os" ) func main() { // Declare two integers variables. var num, base int fmt.Sscan(os.Args[1], &num) fmt.Sscan(os.Args[2], &base) var orignum, origbase = num, base // Build the result right-to-left, in the string res. res := "" for num > 0 { digit := num % base num /= base if digit < 10 { res = fmt.Sprint(digit) + res } else { res = fmt.Sprintf("%c", 'A'+digit-10) + res } } if(res == "") { res = "0" } fmt.Printf("%d in base %d is %s\n", orignum, origbase, res) }