Get the integer value of a hexadecimal number.
(s)
| 168 | return b'0' <= c <= b'9' or b'a' <= c <= b'f' or b'A' <= c <= b'F' |
| 169 | |
| 170 | def unhex(s): |
| 171 | """Get the integer value of a hexadecimal number.""" |
| 172 | bits = 0 |
| 173 | for c in s: |
| 174 | c = bytes((c,)) |
| 175 | if b'0' <= c <= b'9': |
| 176 | i = ord('0') |
| 177 | elif b'a' <= c <= b'f': |
| 178 | i = ord('a')-10 |
| 179 | elif b'A' <= c <= b'F': |
| 180 | i = ord(b'A')-10 |
| 181 | else: |
| 182 | assert False, "non-hex digit "+repr(c) |
| 183 | bits = bits*16 + (ord(c) - i) |
| 184 | return bits |
| 185 | |
| 186 | |
| 187 |
no outgoing calls
no test coverage detected
searching dependent graphs…