Created
March 6, 2019 12:18
-
-
Save nicolascb/21e4c68adaa1aa4b9d147ba8e2bc0dd0 to your computer and use it in GitHub Desktop.
hexdec — Hexadecimal to decimal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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