Get the integer value of a hexadecimal number.
(s)
| 175 | return b'0' <= c <= b'9' or b'a' <= c <= b'f' or b'A' <= c <= b'F' |
| 176 | |
| 177 | def unhex(s): |
| 178 | """Get the integer value of a hexadecimal number.""" |
| 179 | bits = 0 |
| 180 | for c in s: |
| 181 | c = bytes((c,)) |
| 182 | if b'0' <= c <= b'9': |
| 183 | i = ord('0') |
| 184 | elif b'a' <= c <= b'f': |
| 185 | i = ord('a')-10 |
| 186 | elif b'A' <= c <= b'F': |
| 187 | i = ord(b'A')-10 |
| 188 | else: |
| 189 | assert False, "non-hex digit "+repr(c) |
| 190 | bits = bits*16 + (ord(c) - i) |
| 191 | return bits |
| 192 | |
| 193 | |
| 194 |