mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
559 B
37 lines
559 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func printBase(nbr int, base string) {
|
||
|
var result []rune
|
||
|
typeBase := []rune(base)
|
||
|
baseSize := len(base)
|
||
|
pos := 0
|
||
|
for nbr > 0 {
|
||
|
pos = nbr % baseSize
|
||
|
result = append(result, typeBase[pos])
|
||
|
nbr = nbr / baseSize
|
||
|
}
|
||
|
for j := len(result) - 1; j >= 0; j-- {
|
||
5 years ago
|
fmt.Printf("%c", result[j])
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
if len(os.Args) != 2 {
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
} else {
|
||
|
nbr, _ := strconv.Atoi(os.Args[1])
|
||
|
if nbr != 0 {
|
||
|
printBase(nbr, "0123456789abcdef")
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
} else {
|
||
|
fmt.Println(0)
|
||
|
}
|
||
|
}
|
||
|
}
|