c++ - 该程序应给出以下数字的 AND。这是什么意思?

标签 c++ numbers

在我的 C++ 编程课上,我得到了以下代码。作业只是说“该程序应给出以下数字的 AND” 想知道是否可以澄清其含义。我有一个想法,但我想我仍然需要一些建议。代码是故意弄乱的,我必须清理一下。这是清理过的:

// Question2
// This program should give the AND of the inputted numbers.

#include <iostream>

//**Needs namespace statement to directly access cin and cout without using std::
using namespace std;
//**Divided up statements that are running together for better readability
//**Used more spacing in between characters and lines to further increase readability

////void main()
//**Main function should include int as datatype; main is not typically defined as a void function
int main()
{
int i;
int k;

//**Changed spacing to properly enclose entire string
cout << "Enter 0 (false) or 1 (true) for the first value: " << endl;
cin >> i;

cout<< "Enter 0 (false) or 1 (true) for the second value: " << endl;
cin >> k;

//**Spaced out characters and separated couts by lines
//**to help with readability
cout << "AND" << endl;
cout << "k\t| 0\t| 1" << endl;
cout << "---\t| ---\t| ---" << endl;
cout << "0\t| 0\t| 0" << endl;
cout << "1\t| 0\t| 1" << endl;
    if(i==1&k==1)
        cout <<"Result is TRUE" << endl;
    else cout << "Result is FALSE" <<endl;
//**Main function typically includes return statement of 0 to end program execution
return 0; 
}

最佳答案

每个数字都有二进制表示。他们要求位的逻辑和。查找 & 运算符。

关于c++ - 该程序应给出以下数字的 AND。这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19884111/

相关文章:

Java随机数但不为零

c++ - `weak_ptr` 和 `shared_ptr` 访问如何是原子的

c++ - 计算成本

python - xgboost C api 不会产生与 Python 相同的结果

c# - 生成一个 7 位数的数字,前面可以有零

Java极小数算术运算

c++ - 如何生成 24 个字符的 UUID?

c++ - 默认字符串参数

arrays - 如何在 ruby​​ 中对文件名进行排序?

Prolog程序获取一个(整数)数作为两个整数平方和,为什么它不起作用?