Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

String to Hex

438 views
Skip to first unread message

Karen Bailey

unread,
Jun 29, 2004, 2:01:59 PM6/29/04
to
Hi,

I was wondering if anyone knew of any quick functions that would convert a
string to hex?

I found an example on the net, but it is extremely slow when dealing with
1000's or 1000000s of characters.

See below
// string f_convert_char_to_hex( string asString )
// Converts an input string into a hex character string

string sResult, sHexChar
decimal ld_len

decimal i

ld_len = len(asstring)

For i = 1 to Len( asString )

sHexChar = f_convert_to_hex( Asc( Mid( asString, i, 1 ) ) )

If Len( sHexChar ) = 1 Then sHexChar = "0" + sHexChar

sResult = sResult + sHexChar
Next

Return sResult

// string f_convert_to_hex( long alNumber ), recursive:
// Recursive function to translate number into hex representation

If alNumber > 15 Then
Return f_convert_to_hex( alNumber / 16 ) + f_dec_to_hex( Mod(
alNumber, 16 ) )
Else
Return f_dec_to_hex( alNumber )
End If

// string f_dec_to_hex ( integer aiNumber), 0 <= n <= 15
// Converts integer from 0 - 15 into character hex representation

string sHexChar
Choose Case aiNumber
Case 10
sHexChar = 'A'
Case 11
sHexChar = 'B'
Case 12
sHexChar = 'C'
Case 13
sHexChar = 'D'
Case 14
sHexChar = 'E'
Case 15
sHexChar = 'F'
Case Else
sHexChar = String(aiNumber)
End Choose

Return sHexChar

Thanks,

Karen


0 new messages