Skip to content

Instantly share code, notes, and snippets.

@nicolascb
Created March 6, 2019 12:18
Show Gist options
  • Save nicolascb/21e4c68adaa1aa4b9d147ba8e2bc0dd0 to your computer and use it in GitHub Desktop.
Save nicolascb/21e4c68adaa1aa4b9d147ba8e2bc0dd0 to your computer and use it in GitHub Desktop.
hexdec — Hexadecimal to decimal
func hexdec(s string) uint64 {
d := uint64(0)
for i := 0; i < len(s); i++ {
x := uint64(s[i])
if x >= 'a' {
x -= 'a' - 'A'
}
d1 := x - '0'
if d1 > 9 {
d1 = 10 + d1 - ('A' - '0')
}
if 0 > d1 || d1 > 15 {
panic("hexdec")
}
d = (16 * d) + d1
}
return d
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment