题解 | 十六进制转十进制
十六进制转十进制
https://www.nowcoder.com/practice/33e148570d5c4e728116e2f861638c9c
package main
import (
"fmt"
"math"
"strings"
)
func main() {
var a string = "ABCDEF"
var sum int = 0
var temp int = 0
temps := strings.Split(a, "")
for i:=0;i<len(temps);i++{
if temps[i] ==string('A'){
temp = 10
}else if temps[i] ==string('B'){
temp = 11
}else if temps[i] ==string('C'){
temp = 12
}else if temps[i] == string('D'){
temp = 13
}else if temps[i] ==string('E'){
temp = 14
}else if temps[i] ==string('F'){
temp = 15
}else{
fmt.Print("输入内容有误")
}
var b=math.Pow(16, float64(len(temps)-i-1))
sum = temp*int(b)+sum
}
fmt.Printf("%15d",sum)
}
查看16道真题和解析
广发银行公司氛围 23人发布