Convert string Hex to Numeric with inline TSQL

  • Federico Iori

    SSCommitted

    Points: 1625

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

  • Federico Iori

    SSCommitted

    Points: 1625

    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

  • Federico Iori

    SSCommitted

    Points: 1625

    To convert fast from INT to HEX :

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

  • Carlo Romagnano

    SSC-Insane

    Points: 21965

    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

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    Thanks for the script.

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

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