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.
|
|
|
package cap3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_hexMap = map[byte]int{
|
|
|
|
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
|
|
|
|
'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
|
|
|
|
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func Work19(hexStr string) int {
|
|
|
|
// 将输入字符串转换为大写,以便匹配映射表
|
|
|
|
hexStr = strings.ToUpper(hexStr)
|
|
|
|
|
|
|
|
decValue := 0
|
|
|
|
// 从字符串最右端开始转换每个字符
|
|
|
|
for i := 0; i < len(hexStr); i++ {
|
|
|
|
char := hexStr[len(hexStr)-1-i]
|
|
|
|
// 获取字符对应的十进制值,计算十进制
|
|
|
|
if value, exists := _hexMap[char]; exists {
|
|
|
|
decValue += value * int(math.Pow(16, float64(i)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return decValue
|
|
|
|
}
|