条款和规范的平等

时间:2019-01-10 13:02:47

标签: c bit-manipulation bitwise-operators logical-operators

有人可以一步一步解释我,这种平等如何保持?

((a^b)&~b)|(~(a^b)&b)  == a

最好的方法是什么?

3 个答案:

答案 0 :(得分:6)

Option Explicit Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Dim inFile1, inFile2, outFile, objFSO, objInFile, objOutFile Dim strNextLine, fields, arrUserIDList, arrMailList inFile1 = "C:\Scripts\testvbs\wscreatestatus.txt" inFile2 = "C:\Scripts\testvbs\WSBatchCreateBuildsList.txt" outFile = "C:\Scripts\testvbs\WSEmailDeploySuccess.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInFile = objFSO.OpenTextFile(inFile1, ForReading) 'Create an ArrayList of all DomainIDs for successful deployments Set arrUserIDList = CreateObject( "System.Collections.ArrayList" ) Do Until objInFile.AtEndOfStream strNextLine = objInFile.Readline fields = Split(strNextLine , vbTab) If fields(0) = "DEPLOYSUCCESS" Then arrUserIDList.Add fields(5) End If Loop 'close the first input file objInFile.Close 'Now read the second file and read the logonID's from it Set objInFile = objFSO.OpenTextFile(inFile2, ForReading) 'Create an ArrayList of all LogonID's, a TAB character and the EmailAddress Set arrMailList = CreateObject( "System.Collections.ArrayList" ) Do Until objInFile.AtEndOfStream strNextLine = objInFile.Readline fields = Split(strNextLine , ",") If arrUserIDList.Contains(fields(0)) Then ' store the values in arrMailList as TAB separated values arrMailList.Add fields(0) & vbTab & fields(1) End If Loop 'close the file and destroy the object objInFile.Close Set objInFile = Nothing Set objOutFile = objFSO.OpenTextFile(outFile, ForWriting, True) For Each strNextLine In arrMailList objOutFile.WriteLine(strNextLine) Next 'close the file and destroy the object objOutFile.Close Set objOutFile = Nothing 'clean up the other objects Set objFSO = Nothing Set arrUserIDList = Nothing Set arrMailList = Nothing

用X = a ^ b和Y = b代替:

(X&~Y)|(~X&Y) == X^Y //by definition of XOR

然后,其余的很简单:

((a^b)&~b)|(~(a^b)&b) == (a^b)^b

答案 1 :(得分:1)

要检查的程序:

#include <stdio.h>

int main()
{
  int a, b;

  for (a = 0; a != 2; ++a) {
    for (b = 0; b != 2; ++b) {
      printf("((%d^%d)&~%d)|(~(%d^%d)&%d) = %d (a=%d, b=%d)\n",
             a,b,b,a,b,b, ((a^b)&~b)|(~(a^b)&b), a,b);
    }
  }

  return 0;
}

执行产生:

((0^0)&~0)|(~(0^0)&0) = 0 (a=0, b=0)
((0^1)&~1)|(~(0^1)&1) = 0 (a=0, b=1)
((1^0)&~0)|(~(1^0)&0) = 1 (a=1, b=0)
((1^1)&~1)|(~(1^1)&1) = 1 (a=1, b=1)

有关数学解释,请参见RbMm的说明

答案 2 :(得分:1)

只需开发异或并简化:

set()

另一种查看方法是定义outseq。 该语句变为((a^b) & ~b) | (~(a^b) & b) == ((a|b) & (~a|~b) & ~b) | ((a|~b) & (~a|b) & b) == ((a|b) & ~b) | ((a|~b) & b) == a | a == a ,因此您只需简化f(a, b) = (a^b) & ~b

f(a, b) | f(a, ~b)

所以f(a, b)就是f(a, b) == (a^b) & ~b == (a|b) & (~a|~b) & ~b == (a|b) & ~b == a f(a, b) = a就是b

相关问题