English

How To: Convert a hexadecimal string to decimal

Summary

ArcView can convert decimal numbers to a hexadecimal string with the .AsHexString request, but ArcView has no request to convert from hexadecimal string to a decimal number. This document provides a sample script to do this conversion.

Procedure

  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy and paste the code into the new script window.

    Code:
    'Prompt user for the input hexadecimal string
    n = MsgBox.Input("","","")

    decimal = 0

    'Loop through the hexadecimal string
    for each i in 0 .. (n.count-1)
    dchr = n.middle(i,1).UCase.AsAscii
    if (dchr < 65) then
    dchr = dchr - 48 ' offset for numbers
    else
    dchr = dchr - 55 ' offset for letters
    end
    decimal = decimal * 16 + dchr
    end

    'Post the results
    msgbox.info("result ="++decimal.asstring,"")

  3. Compile the script by clicking the compile button.
    [O-Image] Script compile button
  4. Run the script by clicking the run button.
    [O-Image] Run compiled script button