UVA10469 To Carry or not to Carry【数字逻辑运算】
2018-02-10 23:31
1001 查看
6+9=15 seems okay. But how come 4+6=2?
You see, Mofiz had worked hard throughout his digital logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After tracing the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus,
4 = 00000000 00000000 00000000 00000100
+6= 00000000 00000000 00000000 00000110
----------------------------------------
2 = 00000000 00000000 00000000 00000010
Its a good thing that he finally found his mistake, but it was too late. Considering his effort throughout the course, the instructor gave him one more chance. Mofiz has to write an efficient program that would take 2 unsigned 32 bit decimal numbers as input, and produce an unsigned 32 bit decimal number as the output adding in the same was as his circuit does.
Input
In each line of input there will be a pair of integer separated by a single space. Input ends at EOF.
Output
For each line of input, output one line — the value after adding the two numbers in the ‘Mofiz way’.
Sample Input
4 6
6 9
Sample Output
2
15
问题链接:UVA10469 To Carry or not to Carry
问题简述:(略)
问题分析:
仔细看一下原题的算式可以知道如下:
0+0=0
0+1=1
1+0=1
1+1=0
很容易看出来是异或运算。
其实,看电路可以看出来是一个加法器电路,其和计算就是异或。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:/* UVA10469 To Carry or not to Carry */
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
while(~scanf("%d%d", &a, &b))
printf("%d\n", a ^ b);
return 0;
}
/*
0+0=0
0+1=1
1+0=1
1+1=0
*/
You see, Mofiz had worked hard throughout his digital logic course, but when he was asked to implement a 32 bit adder for the laboratory exam, he did some mistake in the design part. After tracing the design for half an hour, he found his flaw!! He was doing bitwise addition but his carry bit always had zero output. Thus,
4 = 00000000 00000000 00000000 00000100
+6= 00000000 00000000 00000000 00000110
----------------------------------------
2 = 00000000 00000000 00000000 00000010
Its a good thing that he finally found his mistake, but it was too late. Considering his effort throughout the course, the instructor gave him one more chance. Mofiz has to write an efficient program that would take 2 unsigned 32 bit decimal numbers as input, and produce an unsigned 32 bit decimal number as the output adding in the same was as his circuit does.
Input
In each line of input there will be a pair of integer separated by a single space. Input ends at EOF.
Output
For each line of input, output one line — the value after adding the two numbers in the ‘Mofiz way’.
Sample Input
4 6
6 9
Sample Output
2
15
问题链接:UVA10469 To Carry or not to Carry
问题简述:(略)
问题分析:
仔细看一下原题的算式可以知道如下:
0+0=0
0+1=1
1+0=1
1+1=0
很容易看出来是异或运算。
其实,看电路可以看出来是一个加法器电路,其和计算就是异或。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:/* UVA10469 To Carry or not to Carry */
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
while(~scanf("%d%d", &a, &b))
printf("%d\n", a ^ b);
return 0;
}
/*
0+0=0
0+1=1
1+0=1
1+1=0
*/
相关文章推荐
- Win32 汇编 - 逻辑运算指令: AND、OR、XOR、NOT、TEST
- lua 逻辑运算 and, or, not【转】
- UVa 10469 To Carry or not to Carry (异或)
- 【再回首Python之美】【逻辑运算】七个逻辑运算符:not, or, and, not or, not and, !=, ==
- 数据运算+-*/,比较运算符==!=,赋值运算,逻辑运算and,or,not,成员运算in,not in,身份运算is is not,位运算&|,运算符的优先级
- UVa 10469 - To Carry or not to Carry
- [汇编]逻辑运算 => AND,OR,XOR,NOT
- 学 Win32 汇编[22] - 逻辑运算指令: AND、OR、XOR、NOT、TEST
- 逻辑运算 NOT\AND\OR\XOR\TEST
- HDU 5978 && 2016ICPC大连 H: To begin or not to begin
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- How to deal with "Could not find component on update server. Contact VMware Support or your system administrator." in Vmware.
- …gen already exists but is not a source folder. Convert to a source folder or rename it [closed]
- Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named
- Could not start the service on local computer. Error 1053: the service did not respond to the start or control request i
- SGU 275 To xor or not to xor(高斯消元)
- This application failed to start because it could not find or load the Qt platform plugin "xcb"
- 安装Yii碰到“the file or directory to be published does not exist bower/jquery/dist”
- This application failed to start because it could not find or load the Qt platform plugin "xcb".
- vc6.0 编译通过,运行时出现:one or more files are out of date or not exist ,These files need to be bulit.