Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // Converts hex strings (starting with "0x") to decimal
  2. //
  3. Function (StringVar hexStr)
  4. if len(hexStr) > 2 and left(hexStr, 2) = "0x" then (
  5. Local stringvar hexVal :=right(hexStr, len(hexStr) - 2);
  6. Local NumberVar strLen := Length (hexVal);
  7. Local NumberVar i;
  8. Local NumberVar result;
  9. For i := 0 To strLen-1 Do (
  10. select (mid (hexVal,i+1,1))
  11. case "a", "A" : result := result+10*(16 ^ (len(hexVal)-(i+1)))
  12. case "b", "B" : result := result+11*(16 ^ (len(hexVal)-(i+1)))
  13. case "c", "C" : result := result+12*(16 ^ (len(hexVal)-(i+1)))
  14. case "d", "D" : result := result+13*(16 ^ (len(hexVal)-(i+1)))
  15. case "e", "E" : result := result+14*(16 ^ (len(hexVal)-(i+1)))
  16. case "f", "F" : result := result+15*(16 ^ (len(hexVal)-(i+1)))
  17. default : result := result+val(mid (hexVal,i+1,1))*(16 ^ (len(hexVal)-(i+1)))
  18. );
  19. result
  20. ) else
  21. 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement