Hex to Decmial Conversion

  • I have a stored procured that reads a text file which contains hexadecimal numbers.

    I need to convert these to decimals. The format is like this:

    49B21B89 004E4E1B 00006F1F 05F2DEB9

    49B9F0CD 004CB3B9 00011F2D 05F3C9E3

    I can use a scientific calculator to do the conversion but need to calculate it within the stored procedure.

    Any suggestions?

    Thanks, Grady Christie

  • Try something like this:

    declare @Bin varbinary(100);

    select @Bin = 0x004E4E1B;

    select cast(@Bin as int);

    Does that help?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • That works perfectly!

    Many Thanks, Grady Christie

  • So, how did you manage to prepend the '0x' to the character data to get it to work correctly?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (3/20/2009)


    So, how did you manage to prepend the '0x' to the character data to get it to work correctly?

    Not sure how Grady did it. I would just use Replace on the spaces in the string. Replace them with space-zero-x, and then add one to the beginning. That's the easy part of this.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Grady Christie (3/20/2009)


    That works perfectly!

    Many Thanks, Grady Christie

    Grady,

    How did you manage to prepend the "0x" to your columns to get this to work correctly?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • C'mon Grady... the reason why I'm asking is because I believe you're getting the wrong answer. Besides, it's a two way street here. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

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