Professional Web Applications Themes

convert hexadecimal to string - Microsoft SQL / MS SQL Server

Hi, How can I convert a hexadecimal value to a string that has a meaning? Thanks, Ionel...

  1. #1

    Default convert hexadecimal to string

    Hi,

    How can I convert a hexadecimal value to a string that has a meaning?

    Thanks,
    Ionel


    ionel Guest

  2. #2

    Default Re: convert hexadecimal to string

    Here's a sproc from BOL that turns Binary data into a Hex string:

    CREATE PROCEDURE sp_hexadecimal
    binvalue varbinary(255),
    hexvalue varchar(255) OUTPUT
    AS
    DECLARE charvalue varchar(255)
    DECLARE i int
    DECLARE length int
    DECLARE hexstring char(16)
    SELECT charvalue = '0x'
    SELECT i = 1
    SELECT length = DATALENGTH(binvalue)
    SELECT hexstring = '0123456789abcdef'
    WHILE (i <= length)
    BEGIN
    DECLARE tempint int
    DECLARE firstint int
    DECLARE secondint int
    SELECT tempint = CONVERT(int, SUBSTRING(binvalue,i,1))
    SELECT firstint = FLOOR(tempint/16)
    SELECT secondint = tempint - (firstint*16)
    SELECT charvalue = charvalue +
    SUBSTRING(hexstring, firstint+1, 1) +
    SUBSTRING(hexstring, secondint+1, 1)
    SELECT i = i + 1
    END
    SELECT hexvalue = charvalue

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --

    "ionel" <com> wrote in message
    news:phx.gbl... 


    David Guest

  3. #3

    Default Re: convert hexadecimal to string

    Hi,

    I was trying to read the 'record data' field that you get from DBCC LOG,
    partially I done it but I get stacked in what it seems to me a code page
    conversion.

    Ionel

    "David Portas" <org> wrote in message
    news:u$phx.gbl... 
    >
    >[/ref]


    ionel Guest

  4. #4

    Default Re: convert hexadecimal to string

    Hi,

    I try it.

    DECLARE HEXED_STRING VARCHAR(40)
    SET HEXED_STRING='414243'
    IF (HEXED_STRING like '%[^0-9A-F]%')
    SELECT '0x'+HEXED_STRING --slightly dangerous
    ELSE
    EXEC ('SELECT CONVERT(VARCHAR(20),0x'+HEXED_STRING+')')

    ABC
    -------
    SHINICHI YONEDA ne.jp
    Microsoft Most Valuable Professional
    MVP for SQL Server 2002-2003


    "ionel" <com> wrote in message
    news:phx.gbl... 

    Shinichi Guest

  5. #5

    Default Re: convert hexadecimal to string

    I tried that one, I can see some of the log but not all.
    Somebody told me to
    "-Convert every 2 hexadecimal digits in your data to an integer value (two
    hexadecimal characters represent 1 byte of varchar data)
    -Convert the resulting integer values to their ASCII character equivalents
    -Try to make sense of the resulting concatenation of ASCII character
    values."

    Ionel

    "Shinichi Yoneda" <ne.jp> wrote in message
    news:phx.gbl... 
    >[/ref]


    ionel Guest

Similar Threads

  1. utility to convert binary to hexadecimal
    By LecterQ in forum Macromedia ColdFusion
    Replies: 2
    Last Post: September 6th, 05:37 PM
  2. utility to convert binary to hexadecimal
    By LecterQ in forum Coldfusion Database Access
    Replies: 1
    Last Post: September 6th, 03:51 PM
  3. convert string to safe string before adding to database
    By forums.macromedia.com in forum Macromedia ColdFusion
    Replies: 4
    Last Post: September 1st, 07:24 PM
  4. how to convert decimal to hexadecimal in perl
    By indie in forum Perl / CGI
    Replies: 2
    Last Post: July 12th, 11:47 AM
  5. Packing a Hexadecimal String
    By Youssef in forum PERL Beginners
    Replies: 2
    Last Post: July 11th, 06:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139