Two's complement addition issue












0












$begingroup$


In a two's complement system, 16-bit binary numbers $0010010010010010$ and $1111110011111100$ can be represented in the decimal system as $9362$ and $-772$, correspondingly.



Now, from what I've read and seen in examples, in a two's complement system, subtracting $770$ from $9362$ will look like this:



$$begin{align}&0010010010010010
\+&1111110011111100
\=&1110000010001110end{align}$$



But this number is negative in a two's complement system and it does not represent $9362$. What am I doing wrong?










share|cite|improve this question











$endgroup$








  • 3




    $begingroup$
    The addition is incorrect.
    $endgroup$
    – saulspatz
    Jan 13 at 2:14






  • 2




    $begingroup$
    There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:19








  • 1




    $begingroup$
    Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:22








  • 1




    $begingroup$
    Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:26








  • 1




    $begingroup$
    @sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
    $endgroup$
    – John Omielan
    Jan 13 at 2:37


















0












$begingroup$


In a two's complement system, 16-bit binary numbers $0010010010010010$ and $1111110011111100$ can be represented in the decimal system as $9362$ and $-772$, correspondingly.



Now, from what I've read and seen in examples, in a two's complement system, subtracting $770$ from $9362$ will look like this:



$$begin{align}&0010010010010010
\+&1111110011111100
\=&1110000010001110end{align}$$



But this number is negative in a two's complement system and it does not represent $9362$. What am I doing wrong?










share|cite|improve this question











$endgroup$








  • 3




    $begingroup$
    The addition is incorrect.
    $endgroup$
    – saulspatz
    Jan 13 at 2:14






  • 2




    $begingroup$
    There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:19








  • 1




    $begingroup$
    Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:22








  • 1




    $begingroup$
    Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:26








  • 1




    $begingroup$
    @sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
    $endgroup$
    – John Omielan
    Jan 13 at 2:37
















0












0








0





$begingroup$


In a two's complement system, 16-bit binary numbers $0010010010010010$ and $1111110011111100$ can be represented in the decimal system as $9362$ and $-772$, correspondingly.



Now, from what I've read and seen in examples, in a two's complement system, subtracting $770$ from $9362$ will look like this:



$$begin{align}&0010010010010010
\+&1111110011111100
\=&1110000010001110end{align}$$



But this number is negative in a two's complement system and it does not represent $9362$. What am I doing wrong?










share|cite|improve this question











$endgroup$




In a two's complement system, 16-bit binary numbers $0010010010010010$ and $1111110011111100$ can be represented in the decimal system as $9362$ and $-772$, correspondingly.



Now, from what I've read and seen in examples, in a two's complement system, subtracting $770$ from $9362$ will look like this:



$$begin{align}&0010010010010010
\+&1111110011111100
\=&1110000010001110end{align}$$



But this number is negative in a two's complement system and it does not represent $9362$. What am I doing wrong?







computer-science binary computational-mathematics floating-point






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jan 15 at 18:30







sequence

















asked Jan 13 at 2:08









sequencesequence

4,24731336




4,24731336








  • 3




    $begingroup$
    The addition is incorrect.
    $endgroup$
    – saulspatz
    Jan 13 at 2:14






  • 2




    $begingroup$
    There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:19








  • 1




    $begingroup$
    Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:22








  • 1




    $begingroup$
    Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:26








  • 1




    $begingroup$
    @sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
    $endgroup$
    – John Omielan
    Jan 13 at 2:37
















  • 3




    $begingroup$
    The addition is incorrect.
    $endgroup$
    – saulspatz
    Jan 13 at 2:14






  • 2




    $begingroup$
    There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:19








  • 1




    $begingroup$
    Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:22








  • 1




    $begingroup$
    Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
    $endgroup$
    – Henning Makholm
    Jan 13 at 2:26








  • 1




    $begingroup$
    @sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
    $endgroup$
    – John Omielan
    Jan 13 at 2:37










3




3




$begingroup$
The addition is incorrect.
$endgroup$
– saulspatz
Jan 13 at 2:14




$begingroup$
The addition is incorrect.
$endgroup$
– saulspatz
Jan 13 at 2:14




2




2




$begingroup$
There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
$endgroup$
– Henning Makholm
Jan 13 at 2:19






$begingroup$
There should be a carry into each of the two leftmost digit positions that make the two leftmost result digits 0. You also seem to have thrown away the carry into the eight bit position (from the left).
$endgroup$
– Henning Makholm
Jan 13 at 2:19






1




1




$begingroup$
Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
$endgroup$
– Henning Makholm
Jan 13 at 2:22






$begingroup$
Curiously, the carries are missing exactly in the two columns where there is an 1 in each addend and a carry coming in from the right. Are you sure your bitwise addition table has the right result for $1+1+1$? Try computing $3+3$ in binary (with four-bit words) and see if you get $6$ like you should.
$endgroup$
– Henning Makholm
Jan 13 at 2:22






1




1




$begingroup$
Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
$endgroup$
– Henning Makholm
Jan 13 at 2:26






$begingroup$
Independently of all this, 1111110011111100 cannot possibly be the representation of $-771$ because it clearly represents an even number: the least significant bit is 0. To negate a 2s-complement number you invert all the bits and then add 1. You've forgotten to add $1$.
$endgroup$
– Henning Makholm
Jan 13 at 2:26






1




1




$begingroup$
@sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
$endgroup$
– John Omielan
Jan 13 at 2:37






$begingroup$
@sequence You still have "subtracting $771$" in your question. I believe you should change the number to $772$ for the statement to be correct. Also, subtracting $772$ from $9362$ results in $8590$, but you say your result "does not represent $9362$.
$endgroup$
– John Omielan
Jan 13 at 2:37












0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3071629%2ftwos-complement-addition-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3071629%2ftwos-complement-addition-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules