{
    "componentChunkName": "component---src-templates-learn-js",
    "path": "/learn/ds/binary_addition",
    "result": {"data":{"mdx":{"frontmatter":{"title":"Binary Addition","date":"September 28, 2022","tags":["ds"],"description":"Binary Addition"},"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Binary Addition\",\n  \"date\": \"2022-09-28\",\n  \"description\": \"Binary Addition\",\n  \"tags\": [\"ds\"],\n  \"type\": \"tuts\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar Video = makeShortcode(\"Video\");\nvar Accordation = makeShortcode(\"Accordation\");\nvar Callouts = makeShortcode(\"Callouts\");\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h2\", null, \"Binary Addition :\"), mdx(\"p\", null, \"Binary Addition (base 2) works same as decimal addition (base 10)\"), mdx(\"h4\", null, \"Rules :\"), mdx(\"table\", {\n    className: \"table-space table-border\"\n  }, mdx(\"tbody\", null, mdx(\"tr\", null, mdx(\"th\", null), mdx(\"th\", null), mdx(\"th\", null), mdx(\"th\", null), mdx(\"th\", null, \"Result\"), mdx(\"th\", null, \"CarryOver \")), mdx(\"tr\", null, mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"+\"), mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"=\"), mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"0\")), mdx(\"tr\", null, mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"+\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"=\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"0\")), mdx(\"tr\", null, mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"+\"), mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"=\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"0\")), mdx(\"tr\", null, mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"+\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"=\"), mdx(\"td\", null, \"0\"), mdx(\"td\", null, \"1\")), mdx(\"tr\", null, mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"+ 1 +\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"=\"), mdx(\"td\", null, \"1\"), mdx(\"td\", null, \"1\")))), mdx(\"br\", null), mdx(Video, {\n    videoSrcURL: binary_addition_1s,\n    poster: binary_addition_poster,\n    mdxType: \"Video\"\n  }), mdx(\"h4\", null, \"Steps : 101 + 101 =?\"), mdx(\"p\", null, \"1.First consider 1's column and add the one's column (1+1) and it gives 10 as per rules. \", mdx(\"br\", null), \"2. Now leave the 0 in the one's column and carry the value 1 to the 10's column (carryOver)\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false diff\",\n    \"file\": \"index.js\",\n    \"show\": \"false\",\n    \"diff\": true\n  }, \"//Binary Addition of 101 + 101\\n     1\\n  1  0  1\\n+ 1  0  1\\n----------\\n        0\\n\")), mdx(\"p\", null, \"3.Now add 10's place 1+(0+0) = 1. So nothing to carry to 100's place and leave the value 1 in 10's place\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+0+0 = 1 (No carryOver)\\n     1\\n  1  0  1\\n+ 1  0  1\\n----------\\n     1  0\\n\")), mdx(\"p\", null, \"4.Now add the 100's place (1+1) =10 ,leave the value 0 in the 100's place and carry 1 to 1000's place\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1=0 (1 carryOver) ,total =10\\n     1\\n  1  0  1\\n+ 1  0  1\\n----------\\n1  0  1  0\\n\")), mdx(\"p\", null, \"5.when we get to last , we can directly write the value ( like 10) at the end.\"), mdx(\"p\", null, \"We can add negative binary numbers using two ways :\"), mdx(\"ol\", null, mdx(\"li\", {\n    parentName: \"ol\"\n  }, \"Binary Addition using 2's Complement\"), mdx(\"li\", {\n    parentName: \"ol\"\n  }, \"Binary Addition using 1's Complement\")), mdx(Accordation, {\n    heading: \"Binary Addition using 2's Complement\",\n    mdxType: \"Accordation\"\n  }, mdx(\"h2\", null, \"Binary Addition using 2's Complement :\"), mdx(\"p\", null, \"we all know how to add two positive binary numbers , but with the 1's complement we can even add two negative binary numbers and one negative with positive.\"), mdx(\"ol\", null, mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#positive--negative--when-positive-is-greater\"\n  }, \"Postive + Negative, when positive is greater\")), mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#positive--negative--when-negative-number-is-greater\"\n  }, \"Positive + Negative , when Negative Number is greater\")), mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#when-two-negative-numbers\"\n  }, \"When Two Negative Numbers \"))), mdx(\"h2\", null, \"positive + Negative , when positive is greater\"), mdx(\"p\", null, \"Steps:\", mdx(\"br\", null), \"\\n1.Find the 1's complement of Negative number , add the positive number and the 1's Complement of Negative number,\", mdx(\"br\", null), \"\\n2.Then ,we again add the end-around carry of the sum to the result to get the final answer .\"), mdx(\"p\", null, \"Ex: add 1010 to (-1001)\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 1010\", mdx(\"sub\", null, \"2\"), \" = 10\", mdx(\"sub\", null, \"10\"), \" and 1001\", mdx(\"sub\", null, \"2\"), \" = 9\", mdx(\"sub\", null, \"10\"), \" \", \"(-9)\"), \"Lets find 1's Complement negative binary number (-1001) to (0110)\", mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n  1  1          //carryOvers\\n  1  0  1  0\\n+ 0  1  1  0\\n1               //1 is end-around carry\\n-------------\\n  0  0  0  0\\n\")), mdx(\"p\", null, \"Now we add end-around carry (1) to the rest of the number which is 0000 .\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//0+1=1 (No carryOver,as per Binary Addition Rules)\\n\\n  0  0  0  0  // addition value of 1010 + 0110\\n+          1  //end around carry\\n-------------\\n  0  0  0  1\\n\")), mdx(\"p\", null, \"Answer is 0001 which is 1 i.e., 10 -9 = 1.\"), mdx(\"h2\", null, \"positive + Negative , when Negative Number is greater\"), mdx(\"p\", null, \"Steps:\", mdx(\"br\", null), \"\\n1.Find the 1's complement of Negative number , add the positive number and the 1's Complement of Negative number,\", mdx(\"br\", null), \"\\n2.Now in this case, there is \", mdx(\"strong\", null, \"no end-around carry\"), \" ,so final answer is obtained by taking the 1's complement of resultant value.\"), mdx(\"p\", null, \"Ex: add 0111 and (-1000)\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 0111\", mdx(\"sub\", null, \"2\"), \" = 7\", mdx(\"sub\", null, \"10\"), \" and 1000\", mdx(\"sub\", null, \"2\"), \" = 8\", mdx(\"sub\", null, \"10\"), \"(-8)\"), \"Lets find 1's Complement negative binary number (-1000) to (0111)\", mdx(\"p\", null, \"Now add 1's complement and postive binary number\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1+1 = 1 (1 carryOver,as per Binary Addition Rules)\\n\\n  1  1  1        //carryOvers\\n  0  1  1  1\\n+ 0  1  1  1\\n-------------\\n  1  1  1  0\\n\")), mdx(\"p\", null, \"Now find the 1's Complement of resultant 1110 is 0001\"), mdx(\"p\", null, \"Answer is 0001 = 1 i.e., 7-8 = -1.\"), mdx(Callouts, {\n    name: \"success\",\n    mdxType: \"Callouts\"\n  }, \"Here resultant value is 0000 1110 ,when we do 1's complement of it ,we get 1111 0001 .Here MSB is 1 it means \", mdx(\"strong\", null, \"Negative number\")), mdx(\"h2\", null, \"When Two Negative Numbers\"), mdx(\"p\", null, \"1.In this case, we represent both the numbers in the 5-bit register by attaching required number of zeros to the left .Then we find 1's complement of both the number & add the values.\\n2.The End-around carry will be again added to the rest of the number\\nNote: in this case, we will always get a carryOver digit after adding, the 1's complement is to be found for the resultant number.\\n3.That value with a negative sign will be answer.\"), mdx(\"p\", null, \"Ex: add -1010 & -0101\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 1010\", mdx(\"sub\", null, \"2\"), \" = 10\", mdx(\"sub\", null, \"10\"), \"(-10) and 0101\", mdx(\"sub\", null, \"2\"), \" = 5\", mdx(\"sub\", null, \"10\"), \"(-5)\"), \"In 5-bit register we get 01010 & 00101\", mdx(\"p\", null, \"Now find 1's Complement of both which we get 10101 & 11010\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n\\n  1  0  1  0  1\\n+ 1  1  0  1  0\\n1                   //end-around carryover\\n----------------\\n  0  1  1  1  1\\n\")), mdx(\"p\", null, \"Now we got resultant = 01111 and endaround carry is 1 . Add endaround carry to resultant\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n     \\u2780  \\u2780  \\u278A         //carryOvers\\n  0  1  1  1  1\\n+             1\\n\\u2776                   //end-around carryover\\n----------------\\n  1  0  0  0  0\\n\")), mdx(\"p\", null, \"Now we have to find 1's complement of 100000 which is 01111\"), mdx(\"p\", null, \"Hence -01111 is final answer and -01111\", mdx(\"sub\", null, \"2\"), \" = ( -15 )\", mdx(\"sub\", null, \"10\"))), mdx(Accordation, {\n    heading: \"Binary Addition using 1's Complement\",\n    mdxType: \"Accordation\"\n  }, mdx(\"h2\", null, \"Binary Addition using 1's Complement :\"), mdx(\"p\", null, \"we all know how to add two positive binary numbers , but with the 1's complement we can even add two negative binary numbers and one negative with positive.\"), mdx(\"ol\", null, mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#positive--negative--when-positive-is-greater\"\n  }, \"Postive + Negative, when positive is greater\")), mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#positive--negative--when-negative-number-is-greater\"\n  }, \"Positive + Negative , when Negative Number is greater\")), mdx(\"li\", {\n    parentName: \"ol\"\n  }, mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"#when-two-negative-numbers\"\n  }, \"When Two Negative Numbers \"))), mdx(\"h2\", null, \"positive + Negative , when positive is greater\"), mdx(\"p\", null, \"Steps:\", mdx(\"br\", null), \"\\n1.Find the 1's complement of Negative number , add the positive number and the 1's Complement of Negative number,\", mdx(\"br\", null), \"\\n2.Then ,we again add the end-around carry of the sum to the result to get the final answer .\"), mdx(\"p\", null, \"Ex: add 1010 to (-1001)\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 1010\", mdx(\"sub\", null, \"2\"), \" = 10\", mdx(\"sub\", null, \"10\"), \" and 1001\", mdx(\"sub\", null, \"2\"), \" = 9\", mdx(\"sub\", null, \"10\"), \" \", \"(-9)\"), \"Lets find 1's Complement negative binary number (-1001) to (0110)\", mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n  1  1          //carryOvers\\n  1  0  1  0\\n+ 0  1  1  0\\n1               //1 is end-around carry\\n-------------\\n  0  0  0  0\\n\")), mdx(\"p\", null, \"Now we add end-around carry (1) to the rest of the number which is 0000 .\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//0+1=1 (No carryOver,as per Binary Addition Rules)\\n\\n  0  0  0  0  // addition value of 1010 + 0110\\n+          1  //end around carry\\n-------------\\n  0  0  0  1\\n\")), mdx(\"p\", null, \"Answer is 0001 which is 1 i.e., 10 -9 = 1.\"), mdx(\"h2\", null, \"positive + Negative , when Negative Number is greater\"), mdx(\"p\", null, \"Steps:\", mdx(\"br\", null), \"\\n1.Find the 1's complement of Negative number , add the positive number and the 1's Complement of Negative number,\", mdx(\"br\", null), \"\\n2.Now in this case, there is \", mdx(\"strong\", null, \"no end-around carry\"), \" ,so final answer is obtained by taking the 1's complement of resultant value.\"), mdx(\"p\", null, \"Ex: add 0111 and (-1000)\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 0111\", mdx(\"sub\", null, \"2\"), \" = 7\", mdx(\"sub\", null, \"10\"), \" and 1000\", mdx(\"sub\", null, \"2\"), \" = 8\", mdx(\"sub\", null, \"10\"), \"(-8)\"), \"Lets find 1's Complement negative binary number (-1000) to (0111)\", mdx(\"p\", null, \"Now add 1's complement and postive binary number\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1+1 = 1 (1 carryOver,as per Binary Addition Rules)\\n\\n  1  1  1        //carryOvers\\n  0  1  1  1\\n+ 0  1  1  1\\n-------------\\n  1  1  1  0\\n\")), mdx(\"p\", null, \"Now find the 1's Complement of resultant 1110 is 0001\"), mdx(\"p\", null, \"Answer is 0001 = 1 i.e., 7-8 = -1.\"), mdx(Callouts, {\n    name: \"success\",\n    mdxType: \"Callouts\"\n  }, \"Here resultant value is 0000 1110 ,when we do 1's complement of it ,we get 1111 0001 .Here MSB is 1 it means \", mdx(\"strong\", null, \"Negative number\")), mdx(\"h2\", null, \"When Two Negative Numbers\"), mdx(\"p\", null, \"1.In this case, we represent both the numbers in the 5-bit register by attaching required number of zeros to the left .Then we find 1's complement of both the number & add the values.\\n2.The End-around carry will be again added to the rest of the number\\nNote: in this case, we will always get a carryOver digit after adding, the 1's complement is to be found for the resultant number.\\n3.That value with a negative sign will be answer.\"), mdx(\"p\", null, \"Ex: add -1010 & -0101\"), mdx(Callouts, {\n    name: \"warning\",\n    mdxType: \"Callouts\"\n  }, \"Note: 1010\", mdx(\"sub\", null, \"2\"), \" = 10\", mdx(\"sub\", null, \"10\"), \"(-10) and 0101\", mdx(\"sub\", null, \"2\"), \" = 5\", mdx(\"sub\", null, \"10\"), \"(-5)\"), \"In 5-bit register we get 01010 & 00101\", mdx(\"p\", null, \"Now find 1's Complement of both which we get 10101 & 11010\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n\\n  1  0  1  0  1\\n+ 1  1  0  1  0\\n1                   //end-around carryover\\n----------------\\n  0  1  1  1  1\\n\")), mdx(\"p\", null, \"Now we got resultant = 01111 and endaround carry is 1 . Add endaround carry to resultant\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-javascript\",\n    \"metastring\": \"file=index.js show=false\",\n    \"file\": \"index.js\",\n    \"show\": \"false\"\n  }, \"//1+1 = 0 (1 carryOver,as per Binary Addition Rules)\\n\\n     \\u2780  \\u2780  \\u278A         //carryOvers\\n  0  1  1  1  1\\n+             1\\n\\u2776                   //end-around carryover\\n----------------\\n  1  0  0  0  0\\n\")), mdx(\"p\", null, \"Now we have to find 1's complement of 100000 which is 01111\"), mdx(\"p\", null, \"Hence -01111 is final answer and -01111\", mdx(\"sub\", null, \"2\"), \" = ( -15 )\", mdx(\"sub\", null, \"10\"))), mdx(Accordation, {\n    heading: \"1's Complement vs 2's Complement\",\n    mdxType: \"Accordation\"\n  }, mdx(\"h2\", null, \"1's Complement vs 2's Complement:\")));\n}\n;\nMDXContent.isMDXComponent = true;","slug":"ds/binary_addition"},"allMdx":{"edges":[{"node":{"slug":"ds/arrays","id":"8ab43cbe-bc50-5590-925e-1a45d7028386"}},{"node":{"slug":"ds/binary_addition","id":"26e70246-f787-5a17-baa8-9375bbacc879"}},{"node":{"slug":"ds/binary_divison","id":"ec6f892f-531e-5661-8a44-d08f906ecba5"}},{"node":{"slug":"ds/binary_operations","id":"b2e4a072-3108-546d-a06a-646e43d834cc"}},{"node":{"slug":"ds/binary_multiplication","id":"0b241fae-5107-5843-b21e-7a5ed393168f"}},{"node":{"slug":"ds/binary_substraction","id":"18f53266-039e-5e0c-af57-37c05a2e80ec"}},{"node":{"slug":"ds/linear_data_structures","id":"0d96c16b-7430-59aa-b81a-73e67dcfd3d2"}},{"node":{"slug":"ds/bit_manipulation","id":"03ba2551-8800-5f50-9724-3a84d09a5989"}},{"node":{"slug":"ds/intro","id":"67e2c78b-07c3-57cf-9984-08e405f77783"}},{"node":{"slug":"ds/roadmap","id":"f7856a33-93ca-5464-8e5a-d5dc41765650"}},{"node":{"slug":"ds/programming_language","id":"ac14fda6-ff3a-5306-964a-3ce25168a6f0"}},{"node":{"slug":"ds/number_systems","id":"12494952-aaee-5db2-91ef-4db461c5b95c"}},{"node":{"slug":"ds/time_space_complex","id":"b7695373-5e9c-56c5-9b7f-5a632785916f"}}]}},"pageContext":{"id":"26e70246-f787-5a17-baa8-9375bbacc879","filePath":"/ds/","previousPostId":"css/intro","nextPostId":"ds/binary_operations"}},
    "staticQueryHashes": ["2033233798"]}