출처 :

http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=57&MAEULNO=22&no=1812

 

    dim testStr     ' 테스트문자열 변수
    dim one_str     ' 문자열 하나
    dim one_ace     ' 문자의 아스키값
    dim one_hex     ' 문자의 헥사값
    dim one_chr     
     dim tmp
    
    testStr = "가나다abc"
    
    '========================================================
    ' 문자 -> 아스키값 -> 16진수(헥사값) -> 다시 문자로
    '========================================================
    for i = 1 to len(testStr)
        one_str = mid(testStr,i,1)      ' 문자를 하나 가져온다.
        one_asc = Asc(one_str)          ' 문자 -> 10진수 (아스키코드로 변환)
        one_hex = hex(one_asc)          ' 10진수 -> 16진수
      if len(one_hex) = 1 then one_hex = "0" & one_hex    ' 16진수 값이 F 미만일경우는 0A, 0B..인데 앞의 숫자 0이 생략되어서 강제로붙여준다.
      one_chr = chr("&H" & one_hex)   ' 16진수 -> 문자

        
        Response.Write "가져온 문자 : " & one_str & "<br>"
        Response.Write "문자 to 아스키값 : " & one_asc & "<br>"
        Response.Write "아스키값 to HEX값 : " & one_hex & "<br>"
        Response.Write "HEX값 to 문자 : " & one_chr & "<hr>"
    next
 
    
    '========================================================
    ' 함수 이용 -_-
    '========================================================
    tmp = StringToHex(testStr)
    Response.Write "문자열을 16진수로<br>"
    Response.Write tmp & "<hr>"
    
    tmp = HexToString(tmp)
    Response.Write "16진수를 문자열로<br>"
    Response.Write tmp
 
 
    '----------------------------------------------
    ' 문자열 -> 16진수
    '----------------------------------------------
    Function StringToHex(pStr)
        dim i, one_hex, retVal
        for i = 1 to len(pStr)
            one_hex = hex(asc(mid(pStr,i,1)))
            retVal = retVal & one_hex
        next
        StringToHex = retVal
    End Function
 
    '----------------------------------------------
    ' 16진수 -> 문자열 변환 함수
    '----------------------------------------------
    Function HexToString(pHex)
        dim one_hex, tmp_hex, i, retVal
        for i = 1 to len(pHex)
            one_hex = mid(pHex,i,1)
            if IsNumeric(one_hex) then
                tmp_hex = mid(pHex,i,2)
                i = i + 1
            else
                tmp_hex = mid(pHex,i,4)
                i = i + 3
            end if
            retVal = retVal & chr("&H" & tmp_hex)        
        next
        HexToString = retVal
    End Function

안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,