Article ID: 10221
SAMPLE: Converting HEX to DECIMAL
SAMPLE
Applies To: ITScriptNet V3

Example Script: How to convert a string containing a Hexidecimal number to its Decimal equivalent.  The zip file contains the sample ITB, designed with ITScriptNet 3.1.

DETAILS

Conversion script:

; get the input and make it upper case
@Input@ = UCase(this.txtInput.Value)

; initialize the decimal portion
@dec@ = 0

; loop through the string
while(Len(@Input@) > 0)
    ; get the first character and truncate the string
    @char@ = Left(@Input@, 1)
    @Input@ = Mid(@Input@, 2, Len(@Input@)-1)

    ; multiply the old data    
    @dec@ = @dec@ * 16

    ; convert the single hex character to decimal
    if((ASC(@char@) >= ASC("A")) && (ASC(@char@) <= ASC("F")))
        ; character A to F
        @char@ = ASC(@char@) - ASC("A") + 10
    elseif((ASC(@char@) >= ASC("0")) && (ASC(@char@) <= ASC("9")))
        ; character 0 - 9
        @char@ = ASC(@char@) - ASC("0")
    else
        ; treat illegal characters as 0
        @char@ = 0
    endif

    ; accumulate
    @dec@ = @dec@ + @char@
wend

This article last updated: 4/6/2010 12:10:15 PM
Please help us improve the Knowledge Base by rating this article.
    © 1997-2026 Z-Space Technologies - a BCA Innovations Company - All rights reserved