Wednesday, June 11, 2014

Find the 1’s Compliment for the binary number in the SQL SERVER

Example :-1

1’s Complete Example

Declare @MainChar Varchar(Max)='0101010101'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output
1010101010


Example :-2

1’s Complete Example

Declare @MainChar Varchar(Max)='000000'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output
111111

Example :-3 

1’s Complete Example

Declare @MainChar Varchar(Max)='11111'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output

00000

No comments:

Post a Comment