Convert string Hex to Numeric with inline TSQL

  • Comments posted to this topic are about the item Convert string Hex to Numeric with inline TSQL

  • A faster way to convert Hex to Dec is

    select CAST(CONVERT(VARBINARY, 'FF00FF', 2) AS INT)

    The string to convert must be at least 2 chars long :

    select CAST(CONVERT(VARBINARY, 'F', 2) AS INT) : error

    select CAST(CONVERT(VARBINARY, '0F', 2) AS INT) : 15

  • To convert fast from INT to HEX :

    right(master.dbo.fn_varbintohexstr(cast( Disconnection_cause as INT) ),2)

  • Federico Iori (8/8/2012)


    A faster way to convert Hex to Dec is

    select CAST(CONVERT(VARBINARY, 'FF00FF', 2) AS INT)

    The string to convert must be at least 2 chars long :

    select CAST(CONVERT(VARBINARY, 'F', 2) AS INT) : error

    select CAST(CONVERT(VARBINARY, '0F', 2) AS INT) : 15

    the faster and faster:

    select CONVERT(VARBINARY, 'fffe', 2)+0 --implicit cast

  • Thanks for the script.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply