Created
May 31, 2011 11:46
-
-
Save wingyplus/1000371 to your computer and use it in GitHub Desktop.
Convert Base Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program support xbase 2 - 10 | |
package main | |
import ( | |
"fmt" | |
"flag" | |
"strconv" | |
"os" | |
) | |
func StoN (Arg string) int { | |
n, err := strconv.Atoi (Arg) | |
if err != nil { | |
os.Exit (0) | |
} | |
return n | |
} | |
func main () { | |
flag.Parse () | |
// check argument flag | |
if flag.NArg () == 0 { | |
fmt.Println ("โปรดใส่เลขฐาน และจำนวนตัวเลข\n") | |
os.Exit (1) | |
} | |
var xbase int = StoN (flag.Arg (0)) | |
var value int = StoN (flag.Arg (1)) | |
// check base value | |
if xbase < 2 { | |
os.Exit (1) | |
} | |
for i := 0; i <= value; i++ { | |
if i < xbase || i / 10 > 0 && i / 10 < xbase && i % 10 < xbase { | |
fmt.Println (i) | |
} else if i / 10 == 10 && i % 10 < xbase { | |
fmt.Println (i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment