SHOW:
|
|
- or go back to the newest paste.
| 1 | .macro hex str | |
| 2 | .local char, value, byteValue, digitPlace | |
| 3 | digitPlace .set 0 | |
| 4 | byteValue .set 0 | |
| 5 | .repeat .strlen( str ), i | |
| 6 | char .set .strat( str, i ) | |
| 7 | .if char <> '_' .and char <> ''' | |
| 8 | .if char >= 'a' && char <= 'f' | |
| 9 | value .set char - 'a' + 10 | |
| 10 | .elseif char >= 'A' && char <= 'F' | |
| 11 | value .set char - 'A' + 10 | |
| 12 | .elseif char >= '0' && char <= '9' | |
| 13 | value .set char - '0' | |
| 14 | .else | |
| 15 | .fatal .sprintf( "hex: Invalid character '%c' encountered", char ) | |
| 16 | .endif | |
| 17 | byteValue .set byteValue | ( value << ( 4 * ( 1 - digitPlace ) ) ) | |
| 18 | digitPlace .set digitPlace ^ 1 | |
| 19 | .if digitPlace = 0 | |
| 20 | .byte byteValue | |
| 21 | byteValue .set 0 | |
| 22 | .endif | |
| 23 | .endif | |
| 24 | .endrepeat | |
| 25 | .if digitPlace = 1 | |
| 26 | .fatal .sprintf( "hex: Number of digits must be a multiple of two" ) | |
| 27 | .endif | |
| 28 | .endmacro | |
| 29 | ||
| 30 | hex "112''''23_34_4f'f" | |
| 31 | hex "09F9_1102_9D74E35BD84156C5635688C0" |