Golang语言下的inttohex()和hextoint()

//菜农[email protected] 2019.6.21于西安雁塔菜地
func inttohex(val, size int) string { //size必须int
	fmts := "%0" + strconv.Itoa(size) + "X"//%#输出0X1234
	return fmt.Sprintf(fmts, val)
}

func hextoint(str string, size int) int {
	var result int = 0
	fmts := "%0" + strconv.Itoa(size) + "X" //%#输入0X1234
	fmt.Sscanf(str, fmts, &result)
	return result
}

你可能感兴趣的:(GoLang语言)