Friday, March 9, 2012

Decimal to ASCII conversion

I need to convert a decimal number to 2 ASCII characters using SQL. For example, 13110 (16 bit word which is 2 bytes) would be a decimal value representing 36 in ASCII.
Any ideas?I don't get the transformation fomula.

You get 36, I suppose the characters '3'+'6'. '3' has the ASCII value 51 (decimal) and '6' has the value 54 (decimal). I do not understand how 51 and 54 can be derivated from 13110. Can you help me?|||I'm sorry, actually it's quite straight forward: 51 is the one word, and 54 is the other word, and together they form your 13110 (decimal) or better to see 3134 (hex).

Anyway, the code is:
SELECT char(floor(13110/256)), char(13110-floor(13110/256)*256)

Cheers!|||That worked! You the Man! Thanks Bunches!

No comments:

Post a Comment