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 |
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2011-04-07 : 02:22:15
|
Hi, My purpose is to splitting bits of a binary value. Means showing values in bit pattern then splitting them.For example:value(decimal) first_bit second_bit third_bit------------------------------------------------------------ 0 0 0 0 1 0 0 1 2 0 1 0 3 0 1 1 4 1 0 0 ... ... 7 1 1 1 ______________________ |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-04-07 : 03:28:41
|
| Post some data how you want to split into binary. With examplesRaghu' S |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-04-07 : 03:41:22
|
[code]select value, bit_4 = case when value& 8 = 0 then 0 else 1 end, bit_3 = case when value& 4 = 0 then 0 else 1 end, bit_2 = case when value& 2 = 0 then 0 else 1 end, bit_1 = case when value& 1 = 0 then 0 else 1 endfrom table[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2011-04-07 : 03:48:49
|
quote: Originally posted by khtan
select value, bit_4 = case when value& 8 = 0 then 0 else 1 end, bit_3 = case when value& 4 = 0 then 0 else 1 end, bit_2 = case when value& 2 = 0 then 0 else 1 end, bit_1 = case when value& 1 = 0 then 0 else 1 endfrom table KH[spoiler]Time is always against us[/spoiler]
Thank you so much!You post exactly my needed.select value, --bit_4 = case when value & 8 = 0 then 0 else 1 end, bit_3 = case when value & 4 = 0 then 0 else 1 end, bit_2 = case when value & 2 = 0 then 0 else 1 end, bit_1 = case when value & 1 = 0 then 0 else 1 endfrom (select 0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7)d(value);/*value bit_3 bit_2 bit_1----------- ----------- ----------- -----------0 0 0 01 0 0 12 0 1 03 0 1 14 1 0 05 1 0 16 1 1 07 1 1 1*/ ______________________ |
 |
|
|
|
|
|
|
|