My sms gateway save message data in log(MSSQL) in Hex code, like this:

0046003A0062006F006B0040007700650062006D0065006400690061002E0070006C

These are Unicode message (16 bits per characters)

Each 4 characters is AsciiHex representation of a character (in hex):

For example:

“0046” = 46hex = ‘F’
“003A” = 3Ahex = ‘:’

how can I convert this in ColdFusion to other format?

Adam

Recommended Answers

Unfortunately I don't know how to decode UTF16. If it were a regular UTF8 string - or the values always had 2 leading zeroes - you could decode it like any 2 char hex string. Loop and grab every 4 characters. Use inputBaseN to get the ascii code, and convert …

Jump to Post

All 4 Replies

Unfortunately I don't know how to decode UTF16. If it were a regular UTF8 string - or the values always had 2 leading zeroes - you could decode it like any 2 char hex string. Loop and grab every 4 characters. Use inputBaseN to get the ascii code, and convert it to a character. Problem is that would not work if the first 2 chars were something other than 00. Not much help I know, but it may give you some ideas.

<cfloop from="1" to="#len(theString)#" index="x" step="4">
                <cfset fourChars = mid(theString, x, 4)>
                <cfset theChar = chr( inputBaseN( fourChars, 16))>
                <cfoutput> character at [#x#] = #theChar# </cfoutput>
            </cfloop>

Thank you, its working....

Thank you, its working....

It works with the sample string, yes. But it wouldn't work if the leading characters are something other than "00" which is possible w/UTF16

I make tests and translate about 4000 short sms messages. Working great. Thx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.