-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexadecimal.go
40 lines (35 loc) · 704 Bytes
/
hexadecimal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"encoding/hex"
"fmt"
"log"
"strconv"
)
func hex2Binary(h *string) {
output, err := strconv.ParseInt(*h, 16, 64)
if err != nil {
log.Fatalln(badInputError)
}
fmt.Printf("Binary: %b", output)
}
func hex2Octal(h *string) {
output, err := strconv.ParseInt(*h, 16, 64)
if err != nil {
log.Fatalln(badInputError)
}
fmt.Printf("Octal: %o", output)
}
func hex2ASCII(h *string) {
output, err := hex.DecodeString(*h)
if err != nil {
log.Fatalln(badInputError)
}
fmt.Printf("ASCII: %s", string(output))
}
func hex2Decimal(h *string) {
output, err := strconv.ParseInt(*h, 16, 64)
if err != nil {
log.Fatalln(badInputError)
}
fmt.Printf("Decimal: %d", output)
}