Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have two string values including only 0 and 1. like this

String 1=00110101011
string 2=00100000000

the result should be like this

String 1=00110101011
string 2=00100000000
----------------------
result =00100000000

I want to apply the AND operation in asp.net. how can i implement this.Pleasw help me to find it.
Posted
Comments
Shanu2rick 17-Jan-13 5:44am    
COnvert your value to int and apply the & operator.
Sergey Alexandrovich Kryukov 17-Jan-13 7:38am    
How a bitwise operation can possibly be related to ASP.NET?!
—SA

Try something like this:
C#
string str1 = "00110101011";
string str2 = "00100000000";

int i1 = Convert.ToInt32(str1, 2);
int i2 = Convert.ToInt32(str2, 2);

string result = Convert.ToString(i1 | i2, 2).PadLeft(8,0);
 
Share this answer
 
Here is something you can give a shot at:
C#
string s1 = "0011 0111 0111";
            string s2 = "0111 0000 1010";
            s1 = s1.Replace(" ", "");
            s2 = s2.Replace(" ", "");
            int i1 = Convert.ToInt32(s1, 2);
            int i2 = Convert.ToInt32(s2, 2);

            string result = Convert.ToString(i1 & i2, 2).PadLeft(12,'0');

I guess you are aware of every method used here except for the last Method PadLeft(12,'0'), here
C#
PadLeft(Int32,char);//this method show the string from left upto char number towards right you are passing in first Argument "Int32" ie the total length of the string and the second argument will tell you the padding character
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900