Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 A SP to Convert Hex values to Ascii Characters

Author  Topic 

ragh
Starting Member

34 Posts

Posted - 2002-10-24 : 02:47:23
Hi !

Let me know how would you write a SP to convert an Hexadecimal values to ASCII characters, its almost like decrypting the Hex values. Only in MSSQL 7.0 please

bye !

Ragh

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-10-24 : 05:11:18
If you want some way of turning a binary or varbinary value into a char or varchar, just cast it:

DECLARE @binvalue varbinary(4)
SET @binvalue = 0x74686973
SELECT CAST(@binvalue AS varchar(4))

If you want some way of turning a string containing a hex representation of a binary value into the string with that bit pattern, try casting the output of the function I posted in this thread: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=20751

DECLARE @hexstr varchar(10)
SET @hexstr = '0x74686973'
SELECT CAST(dbo.hexstrtovarbin(@binstr) AS varchar(4))

Oops, sorry, you said 7.0. Well, it's pretty straight-forward to turn this into an SP with an output parameter.

If the bit pattern represents a Unicode string, then it shouldn't be a problem as long as it's encoded as little-endian UCS-2. Since this is the internal format and not a datastream, trying to use a BOM at the start to indicate a big- or little-endian value is unlikely to give the desired result.

DECLARE @binvalue2 varbinary(8)
SET @binvalue2 = 0xAC20320035003000
SELECT CAST(@binvalue2 AS nvarchar(4))


Go to Top of Page
   

- Advertisement -