Advertisement
krylormaximus

Untitled

Apr 30th, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2. '**************************************
  3. ' Name: Convert Hex to Decimal (32-bit U
  4. ' nsigned)
  5. ' Description:Converts Hex [0 - FFFFFFFF
  6. ' ] to Decimal [0 - 4294967295] using Curr
  7. ' ency type to avoid the sign bit.
  8. ' By: Larry Serflaten (from psc cd)
  9. '
  10. '
  11. ' Inputs:A valid 1-8 character Hex Strin
  12. ' g
  13. '
  14. ' Returns:A Currency value in the range
  15. ' of 0 - 4294967295
  16. '
  17. 'Assumes:None
  18. '
  19. 'Side Effects:None
  20. '**************************************
  21.  
  22.  
  23.  
  24. Function ConvertHex (H$) As Currency
  25. Dim Tmp$
  26. Dim lo1 As Integer, lo2 As Integer
  27. Dim hi1 As Long, hi2 As Long
  28. Const Hx = "&H"
  29. Const BigShift = 65536
  30. Const LilShift = 256, Two = 2
  31. Tmp = H
  32. 'In case "&H" is present
  33. If UCase(Left$(H, 2)) = "&H" Then Tmp = Mid$(H, 3)
  34. 'In case there are too few characters
  35. Tmp = Right$("0000000" & Tmp, 8)
  36. 'In case it wasn't a valid number
  37.  
  38.  
  39. If IsNumeric(Hx & Tmp) Then
  40. lo1 = CInt(Hx & Right$(Tmp, Two))
  41. hi1 = CLng(Hx & Mid$(Tmp, 5, Two))
  42. lo2 = CInt(Hx & Mid$(Tmp, 3, Two))
  43. hi2 = CLng(Hx & Left$(Tmp, Two))
  44. ConvertHex = CCur(hi2 * LilShift + lo2) * BigShift + (hi1 * LilShift) + lo1
  45. End If
  46. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement