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

Example Script: How to convert a string containing a Decimal number to its Hexidecimal 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 hex portion
@hex@ = ""

; initialize the decimal portion
@dec@ = VAL(@Input@)

; loop through the string
while(VAL(@dec@) >  0)
    ; get the character value by doing a MOD division with 16 to get the remainder
    @mod@ = MOD(@dec@, 16)

    ; get the quotient for the next loop
    @dec@ = @dec@ / 16

    ; convert the number to hex
    if((@mod@ >= 0) && (@mod@ <= 9))
        ; keep the digit unconverted
        @char@ = @mod@
    elseif((@mod@ >= 10) && (@mod@ <= 15))
        ; convert to the HEX A-F
        @char@ = @mod@ + ASC("A") - 10
        @char@ = Chr(@char@)
    else
        @char@ = "0"
    endif

    ; add to the result
    @hex@ = @char@ & @hex@
wend

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