Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Converts hex strings (starting with "0x") to decimal
- //
- Function (StringVar hexStr)
- if len(hexStr) > 2 and left(hexStr, 2) = "0x" then (
- Local stringvar hexVal :=right(hexStr, len(hexStr) - 2);
- Local NumberVar strLen := Length (hexVal);
- Local NumberVar i;
- Local NumberVar result;
- For i := 0 To strLen-1 Do (
- select (mid (hexVal,i+1,1))
- case "a", "A" : result := result+10*(16 ^ (len(hexVal)-(i+1)))
- case "b", "B" : result := result+11*(16 ^ (len(hexVal)-(i+1)))
- case "c", "C" : result := result+12*(16 ^ (len(hexVal)-(i+1)))
- case "d", "D" : result := result+13*(16 ^ (len(hexVal)-(i+1)))
- case "e", "E" : result := result+14*(16 ^ (len(hexVal)-(i+1)))
- case "f", "F" : result := result+15*(16 ^ (len(hexVal)-(i+1)))
- default : result := result+val(mid (hexVal,i+1,1))*(16 ^ (len(hexVal)-(i+1)))
- );
- result
- ) else
- 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement