Question

In: Computer Science

Add 12345869 and −987654321 in binary

Add 12345869 and 987654321 in binary

Solutions

Expert Solution

Steps
1. Convert first number (12345869) to binary.
2. Convert second number (-987654321) to binary.

3. Add both the binary numbers.


Step 1 :

  • (12345869)10 is equal to (0000 0000 1011 1100 0110 0010 0000 1101)2 in binary.

Step 2:

  • (987654321)10 is equal to (0011 1010 1101 1110 0110 1000 1011 0001)2 in binary.
  • But to convert the positive number into negative, we need to find the 2's Complement of the (987654321).


2's Complement of number = 1's Complement of number + 1

  • 1's Complement of any binary number is computed by inverting the each bit of binary. For example 1's complement of 1100 is equal to 0011. Hence 1's Complement of (0011 1010 1101 1110 0110 1000 1011 0001) is equal to (1100 0101 0010 0001 1001 0111 0100 1110).
  • By adding the 1 to the above binary number, 2's Complemented computed is (1100 0101 0010 0001 1001 0111 0100 1111).


Step 3:

  • To add the two bits, following bit addition table is used.

  • Hence the Addition of both the binary number is done as following:

  • Hence the binary sum is (1100 0101 1101 1101 1111 1001 0101 1100)2 . As the Most Significant Bit (Left Most Bit) of the sum is 1, hence the resulting number is negative.
  • To reconfirm the binary addition, we need to convert the binary number into decimal. Hence to find the decimal of negative binary number, we need to find the 2's Complement and then convert the binary into decimal.


2's Complement = 1's Complement + 1

  • 1's Complement of (1100 0101 1101 1101 1111 1001 0101 1100)2 is (0011 1010 0010 0010 0000 0110 1010 0011)2 .
  • 2's Complement is (0011 1010 0010 0010 0000 0110 1010 0100)2 after adding 1 to 1's Complement.
  • (0011 1010 0010 0010 0000 0110 1010 0100)2 is equivalent to (975308452)10 in Decimal number system. Hence the number is -975308452
  • By the decimal number system of addition (12345869+(-987654321)) is equal to - 975308452. Hence the additions result is correct.

Related Solutions

i need to convert decimal to twos complement binary and then add the binary digits but...
i need to convert decimal to twos complement binary and then add the binary digits but I am unable to do it. I am only allowed to use string, can anyone help me out please. i need the code urgently. #include #include #include #include using namespace std; string reverse(string s) { string x = ""; for (long i = s.length() - 1; i >= 0; i--) { x += s[i]; } return x; } string twosComplementStringsAddition(string A, string B) {...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Write an implementation of the set class, with associated iterators using a binary search tree. Add...
Write an implementation of the set class, with associated iterators using a binary search tree. Add to each node a link to the parent node. (C++)
In C++ Consider the binary search tree implementation in file bintree.cp a)Add to the TreeNode class...
In C++ Consider the binary search tree implementation in file bintree.cp a)Add to the TreeNode class a pointer to the parent node. Modify the insert and erase functions to properly set those pointers. b)Then define a TreeIterator class that contains a pointer to a TreeNode and has member functions get and next. i)The iterator’s get member function should return the data value of the node to which it points. ii)The iterator’s next member function should find the next element in...
Design a system which can add two 2-digit binary numbers (no carry in). Use a truth...
Design a system which can add two 2-digit binary numbers (no carry in). Use a truth table approach and use karnaugh-map Write a Boolean equation for each output and draw circuit.
We want to build an adder to simultaneously add three multi-digit binary numbers. Design a single...
We want to build an adder to simultaneously add three multi-digit binary numbers. Design a single bit of that adder. It has three inputs for that digit, x, y, and z, plus two carry inputs, u and v (since you may have a carry of 0, 1, or 2). There are three outputs, a sum, s, and two carries, f, and g. Show a truth table and find the minimum sum of products expressions for the three outputs. I need...
Add binary numbers 0 1010 1100+ 0 0011 1010 a. 0 1110 0110,NZVC= 0000 b. 1...
Add binary numbers 0 1010 1100+ 0 0011 1010 a. 0 1110 0110,NZVC= 0000 b. 1 0101 1011,NZVC= 1001 c. 0 0110 1111,NZVC= 0011 d. 1 0000 0110,NZVC= 1010 e. None of the above
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip>...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<algorithm> using namespace std; const int row = 10; const int col = 7;   ifstream name; ifstream grade; ofstream out; void readData(string stname[row], int stgrade[row][col]); void stsum(int stgrade[row][col], int total[row]); void staverage(int total[row], double average[row]); void stlettergrade(double average[row],char ltrgrade[row]); void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]); void swapltrgrade(char* xp, char* yp); int main() {    int STG[row][col] = { {0},{0}...
ARITHMETIC INSTRUCTIONS a) ADD with register/memory       ADD r [or] ADD M b) ADD immediate.      ...
ARITHMETIC INSTRUCTIONS a) ADD with register/memory       ADD r [or] ADD M b) ADD immediate.       ADI 8 bit data c) ADD with carry       ADC r [or] ADC M Exercise 1: Write Assembly Language Program to add any 3 numbers. Exercise 2: Write Assembly Language Program to add the value 05H with value stored in register C.
​Define a tree. Distinguish between a tree and a binary tree. Distinguish between a binary tree and a binary search tree.
Define a tree. Distinguish between a tree and a binary tree. Distinguish between a binary tree and a binary search tree.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT