• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1function hex2int(str,   i) {
2  str = tolower(str)
3
4  for (i = 1; i <= 16; i++) {
5    char = substr("0123456789abcdef", i, 1)
6    lookup[char] = i-1
7  }
8
9  result = 0
10  for (i = 1; i <= length(str); i++) {
11    result = result * 16
12    char   = substr(str, i, 1)
13    result = result + lookup[char]
14  }
15  return result
16}
17
18function parse_const(str) {
19  sign = sub(/^-/, "", str)
20  hex  = sub(/^0x/, "", str)
21  if (hex)
22    n = hex2int(str)
23  else
24    n = str+0
25  return sign ? -n : n
26}
27