本文介绍了asp.net中的按位操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串值,仅包括0和1.像这样
字符串1 = 00110101011
字符串2 = 00100000000
结果应该是这样的
String 1 = 00110101011
string 2 = 00100000000
----------------------
result = 00100000000
我想在asp.net中应用AND操作。我怎么能实现这个.Pleasw帮我找到它。
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.
推荐答案
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);
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');
我想你知道这里使用的每个方法,除了最后一个方法 PadLeft(12,''0'')
,这里
I guess you are aware of every method used here except for the last Method PadLeft(12,''0'')
, here
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
这篇关于asp.net中的按位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!