在下面的代码中,由于x的按位补码为-1(使用2' s补码)且y为2,我期望z的值为零,但我得到z的值为2当我运行程序时。任何人都可以解释一下我错在哪里?
CODE
void DirSearch(string rootDirectory, string filesExtension, string[] textToSearch, BackgroundWorker worker, DoWorkEventArgs e)
{
List<string> resultsoftextfound = new List<string>();
List<string> filePathList = new List<string>();
List<string> restrictedFiles = new List<string>();
int numberoffiles = 0;
int numberofdirs = 0;
int countTextToSearch = 0;
try
{
filePathList = SearchAccessibleFilesNoDistinct(rootDirectory, null).ToList();
}
catch (Exception err)
{
string ad = err.ToString();
}
foreach (string file in filePathList)
{
try
{
_busy.WaitOne();
if (worker.CancellationPending == true)
{
e.Cancel = true;
return;
}
for (int i = 0; i < textToSearch.Length; i++)
{
List<MyProgress> prog = new List<MyProgress>();
if (File.ReadAllText(file).Contains(textToSearch[i].ToLower()))
{
resultsoftextfound.Add(file + " " + textToSearch[i]);
numberoffiles++;
prog.Add(new MyProgress { Report1 = file, Report2 = numberoffiles.ToString() });
backgroundWorker1.ReportProgress(0, prog);
}
}
numberofdirs++;
label1.Invoke((MethodInvoker)delegate
{
label1.Text = numberofdirs.ToString();
label1.Visible = true;
});
}
catch (Exception)
{
restrictedFiles.Add(file);
continue;
}
}
}
答案 0 :(得分:4)
0
的按位赞美是1
所有AND
所以AND
使用它可以准确地为2
提供其他输入,在这种情况下0 = 00000000
~0 = 11111111
2 = 00000010
~0&2 = 00000010
}。
假设8位节省空间:
{{1}}