说下面的东西通过
#include <iostream>
class Nand{
public :
bool A;
bool B;
bool s() const;
};
bool Nand::s() const {
return (!(A&&B));
};
int main()
{
std::cout << std::boolalpha;
Nand Nand_1;
Nand_1.A = true;
Nand_1.B=false;
bool Y = Nand_1.s();
std::cout << "Input A of Nand_1 is equivalent to : " << Nand_1.A << std::endl;
std::cout << "Input B of Nand_1 is equivalent to : " << Nand_1.B << std::endl;
std::cout << "Output Y of Nand_1 is equivalent to : " << Y << std::endl;
return 0;
}
这个也是
#include <iostream>
class Nand{
public :
bool s(bool iA, bool iB) const;
};
bool Nand::s(bool iA, bool iB) const {
return (!(iA&&iB));
};
int main()
{
std::cout << std::boolalpha;
Nand Nand_1;
bool Y = Nand_1.s(true, false);
//std::cout << "Input A of Nand_1 is equivalent to : " << Nand_1.A << std::endl;
//std::cout << "Input B of Nand_1 is equivalent to : " << Nand_1.B << std::endl;
std::cout << "Output Y of Nand_1 is equivalent to : " << Y << std::endl;
return 0;
}
Sboxes由简单的2输入Nand连接在一起制成.我想模板Nand类以生成复杂的Sboxes。实际上,()函数是在这个片段中用两个输入显示的。我管理至少128位的数组输入。
裂变材料写得不好。第二个允许在中间链接,但不允许显示s的输入!
如何读取第二个内容中的参数?我可以用第一个片段,但我认为它不是很好的编写(为了模板以后)。
这让我很激动:
发布于 2017-07-20 16:02:46
对于这项任务,OOP完全没有必要。您可以使用按位运算符,它已经完成了您要求的操作。而且,要存储复杂的位,可以使用带有整数类型的十六进制。
unsigned short int a = 0xa; // 00001010b
unsigned short int b = 0xd; // 00001101b
// unsigned short int c,d,e,...
std::cout << std::hex << (a & b) << std::endl; // AND
std::cout << std::hex << (a | b) << std::endl; // OR
std::cout << std::hex << (a ^ b) << std::endl; // XOR
std::cout << std::hex << (~a) << std::endl; // NOT
std::cout << std::hex << (~b) << std::endl; // NOT
std::cout << std::hex << ~(a & b) << std::endl; // XAND
//std::cout << std::hex << ~(c & d & e/* & ..*/) << std::endl; // complicated XAND
您可以在门中使用任意数量的变量,因为编译器将它作为要在下一个表达式中求值的表达式返回。有关这些操作符和表达式的详细信息,请查看特定编译器的手册页。
如果您需要更多比特,请研究如何在您的系统上实现64位(如果可能的话),因为系统不高于64位。如果需要更多,可以使用数组。
unsigned long long int x[2] = {0xffff,0xffff}; // this assignment depends on your compiler
#include <stdint.h>
int64_t x[2] = {0xffff,0xffff}; // guaranteed 64-bit as of C99
https://stackoverflow.com/questions/40007435
复制相似问题