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) {...
6. Add using binary addition 26 and 56 45 and 65      7. Subtract using binary...
6. Add using binary addition 26 and 56 45 and 65      7. Subtract using binary two’s complement 23 from 45 34 from 65
c++ Create a program where you can add binary while they're still in binary form and...
c++ Create a program where you can add binary while they're still in binary form and convert them to decimal, adds them, then converts then back to binary. (without built in conversions). Convert 34 to Binary Convert 22 to Binary Convert 1001 to Decimal Convert 111011 to Decimal Add 11 and 1110 in Binary Return the Answer in Binary Subtract 111 from 1010 in Binary, then Convert the Answer to Decimal
Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of...
Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of each of these lists to generate a total sum Print the lists, and the total sum of each value C++ contains some built-in functions (such as itoa and std::hex) which make this assignment trivial. You may NOT use these in your programs. You code must perform the conversion through your own algorithm. The input values are: 5 9 24 2 39 83 60 8...
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers...
Represent -60 in binary using 8-bit signed magnitude. Add the following unsigned 8 bit binary numbers as shown. 01110101 + 00111011 Add the following unsigned 8 bit binary numbers as shown. 01000100 + 10111011
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...
(C++) Hey, so I'm trying to make a Remove() and Add() function for a Binary Search...
(C++) Hey, so I'm trying to make a Remove() and Add() function for a Binary Search Tree (NOT USING RECURSION), can you help? For 3 cases: no child, 1 child and 2 children also for Remove(). This is the function to find the node to be deleted/added TreeNode* PrivateFind(const T& tWhat)    {        //Start from head        TreeNode* tWalk = mHead;        while (tWalk != nullptr)        {            //If found then return...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT