Challenge: write a user-defined function that accepts positive integers as large as decimal(32,0) and returns the hexadecimal expansion for that value. (Decimal(38, 0) is difficult because then you can't do any division at all on it.) You may break it out into multiple functions if you like.
For example, here are the outputs from my function for two inputs:
PRINT dbo.NumberToHex(65535) -- 0000FFFF
PRINT dbo.NumberToHex(convert(decimal(32,0), 99999999999999999999999999999999)) -- 00000004EE2D6D415B85ACEF80FFFFFFFF
I'll be flexible for now and not pay attention to how many leading zeroes your function does or does not add. At least one digit must be returned.
Entries will be judged in the following categories:
• Shortest code, not counting line breaks
• Fastest code overall, 50000 or more iterations each of random values between 0 and various limits from 0 up to the large all-9s number above (generating a curve)
• Style, as judged by me and influenced by comments from participants
• Bonus: entries which return a number of leading zeroes relevant to the type of the input variable (see that my first example is eight hex digits long with four leading zeroes).
I have already written function testing code which allows me to specify as many functions as I like and as many input values as I like, and run through them spitting out elapsed time for each. The speed results will go into a spreadsheet and be graphed.
I wrote a version of this function about a year ago, and today I have been tweaking it. I'm almost done (and I won't look at any entries here until it's finished).
I hope we have some good fun with this! If people like it, I'll do more of them. Kind of a more involved SQL teaser.
Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.
For example, here are the outputs from my function for two inputs:
PRINT dbo.NumberToHex(65535) -- 0000FFFF
PRINT dbo.NumberToHex(convert(decimal(32,0), 99999999999999999999999999999999)) -- 00000004EE2D6D415B85ACEF80FFFFFFFF
I'll be flexible for now and not pay attention to how many leading zeroes your function does or does not add. At least one digit must be returned.
Entries will be judged in the following categories:
• Shortest code, not counting line breaks
• Fastest code overall, 50000 or more iterations each of random values between 0 and various limits from 0 up to the large all-9s number above (generating a curve)
• Style, as judged by me and influenced by comments from participants
• Bonus: entries which return a number of leading zeroes relevant to the type of the input variable (see that my first example is eight hex digits long with four leading zeroes).
I have already written function testing code which allows me to specify as many functions as I like and as many input values as I like, and run through them spitting out elapsed time for each. The speed results will go into a spreadsheet and be graphed.
I wrote a version of this function about a year ago, and today I have been tweaking it. I'm almost done (and I won't look at any entries here until it's finished).
I hope we have some good fun with this! If people like it, I'll do more of them. Kind of a more involved SQL teaser.
Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.