Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-10-03 : 07:42:28
|
| John writes "Hi;Okay folks, this ones taking me a bit(?) longer than I think it should. I need a way to convert a Binary map representation that is now stored as integer, to either decimal or character representation. So;integer value on db is: 84Character Map needs to be 01010100I'm sure someone has a quick approach that will humble me today.Thanks so much!" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-03 : 07:44:42
|
| [code]CREATE FUNCTION dbo.fnINT2BIN( @Value BIGINT)RETURNS VARCHAR(64)ASBEGIN DECLARE @BIN VARCHAR(64), @Index SMALLINT, @SUM BIGINT SELECT @BIN = '', @Index = CEILING(LOG(@Value) / LOG(2.0)), @SUM = POWER(2.0, @Index) WHILE @Index >= 0 SELECT @BIN = @BIN + CASE WHEN @Value >= @SUM THEN '1' ELSE '0' END, @Value = @Value - CASE WHEN @Value >= @SUM THEN @SUM ELSE 0 END, @SUM = @SUM / 2, @Index = @Index - 1 RETURN @BINEND[/code]Good luck on the exam!I hope 2 minutes 14 seconds was fast enough for you.Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-03 : 08:49:24
|
>>I hope 2 minutes 14 seconds was fast enough for you.Becuase you are very Fast MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|