- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- string a,b;
- int c[8]={0};
- int sa=0,sb=0,t;
- cin >> a >> b;
- for (int i=0;i<8;i++){
- sa += (a[i]-'0')*pow(2,7-i);
- sb += (b[i]-'0')*pow(2,7-i);
- }
- cout << sa << " + " << sb << " = " << sa+sb << endl;
- t = sa+sb;
- if(t>=255){
- cout << "11111111" << endl;
- }
- else{
- int up = 0;
- for(int i=7;i>=0;i--){
- if (a[i]-'0'==1 && b[i]-'0' == 1 && up == 0){
- c[i] = 0;
- up = 1;
- }
- else if (a[i]-'0'==1 && b[i]-'0' == 1 && up == 1){
- c[i] = 1;
- up = 1;
- }
- else if(a[i]-'0'==1 && b[i]-'0'==0 && up == 1){
- c[i] = 0;
- up = 1;
- }
- else if(a[i]-'0'==1 && b[i]-'0'==0 && up == 0){
- c[i] = 1;
- up = 0;
- }
- else if(a[i]-'0'==0 && b[i]-'0'==1 && up == 1){
- c[i] = 0;
- up = 1;
- }
- else if(a[i]-'0'==0 && b[i]-'0'==1 && up == 0){
- c[i] = 1;
- up = 0;
- }
- else if(a[i]-'0'==0 && b[i]-'0'==0 && up == 0){
- c[i] = 0;
- up = 0;
- }
- else if(a[i]-'0'==0 && b[i]-'0'==0 && up == 1){
- c[i] = 1;
- up = 0;
- }
- }
- for (int i=0;i<8;i++){
- cout << c[i];
- }
- }
- return 0;
- }
複製代碼 |