You have to first take your input as an int and then print the hex value :
package main
import (
"fmt"
"os"
)
func main() {
var e int
fmt.Scanf("%d", &e)
fmt.Fprintf(os.Stdout, "%#X
", e)
}
Output is :
go run main.go
10
0XA
For multiple inputs :
package main
import (
"fmt"
"os"
)
func main() {
var e int
var s string
fmt.Scanf("%d %s", &e, &s)
fmt.Fprintf(os.Stdout, "%#X \t%s
", e, s)
}
Output is :
go run main.go
10 hello
0XA hello
Update : fmt.Scanf() vs fmt.Scan()
Scan is able to loop :
package main
import (
"fmt"
"os"
)
func main() {
var e int
var f int
var g int
fmt.Scan(&e, &f, &g)
fmt.Fprintf(os.Stdout, "%d - %d - %d", e, f, g)
}
Output is :
go run main.go
10
11
12
10 - 11 - 12
Scanf is able to """filter""" from a formated string :
package main
import (
"fmt"
"os"
)
func main() {
var e int
var f int
fmt.Scanf("%d Scanf %d", &e, &f)
fmt.Fprintf(os.Stdout, "%d - %d", e, f)
}
Output is :
go run main.go
10 Scanf 11
10 - 11