Closed Form Addition of BCD numbers












1












$begingroup$


Binary Coded Decimal (BCD) number representation is a 4-bit encoding which maps numbers 0-9 to their counterpart binary codes. Addition of BCD numbers can be formulated as follows:




  • z = a + b (If z < 10)

  • z = a + b - 10 (If z >= 10)


For instance, If we add 7 (0111) and 8 (1000), we get 15-10=5, and a carry for a higher order. My question: How can we formulate the aforementioned formula without comparison operator; i.e. what is a closed form formula for addition of 2 BCD numbers (like for example z = a+b-3ab+64a^2-128b^3, this is just an example form of what I need)?



Thanks










share|cite|improve this question









$endgroup$

















    1












    $begingroup$


    Binary Coded Decimal (BCD) number representation is a 4-bit encoding which maps numbers 0-9 to their counterpart binary codes. Addition of BCD numbers can be formulated as follows:




    • z = a + b (If z < 10)

    • z = a + b - 10 (If z >= 10)


    For instance, If we add 7 (0111) and 8 (1000), we get 15-10=5, and a carry for a higher order. My question: How can we formulate the aforementioned formula without comparison operator; i.e. what is a closed form formula for addition of 2 BCD numbers (like for example z = a+b-3ab+64a^2-128b^3, this is just an example form of what I need)?



    Thanks










    share|cite|improve this question









    $endgroup$















      1












      1








      1


      1



      $begingroup$


      Binary Coded Decimal (BCD) number representation is a 4-bit encoding which maps numbers 0-9 to their counterpart binary codes. Addition of BCD numbers can be formulated as follows:




      • z = a + b (If z < 10)

      • z = a + b - 10 (If z >= 10)


      For instance, If we add 7 (0111) and 8 (1000), we get 15-10=5, and a carry for a higher order. My question: How can we formulate the aforementioned formula without comparison operator; i.e. what is a closed form formula for addition of 2 BCD numbers (like for example z = a+b-3ab+64a^2-128b^3, this is just an example form of what I need)?



      Thanks










      share|cite|improve this question









      $endgroup$




      Binary Coded Decimal (BCD) number representation is a 4-bit encoding which maps numbers 0-9 to their counterpart binary codes. Addition of BCD numbers can be formulated as follows:




      • z = a + b (If z < 10)

      • z = a + b - 10 (If z >= 10)


      For instance, If we add 7 (0111) and 8 (1000), we get 15-10=5, and a carry for a higher order. My question: How can we formulate the aforementioned formula without comparison operator; i.e. what is a closed form formula for addition of 2 BCD numbers (like for example z = a+b-3ab+64a^2-128b^3, this is just an example form of what I need)?



      Thanks







      logic arithmetic decimal-expansion binary-programming






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Jan 20 at 20:16









      msjmsj

      61




      61






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)ldots (a-9)b(b-1)(b-2)(b-4)ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
            $endgroup$
            – msj
            Jan 20 at 21:23










          • $begingroup$
            They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
            $endgroup$
            – Ross Millikan
            Jan 20 at 21:33













          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%2f3081088%2fclosed-form-addition-of-bcd-numbers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0












          $begingroup$

          It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)ldots (a-9)b(b-1)(b-2)(b-4)ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
            $endgroup$
            – msj
            Jan 20 at 21:23










          • $begingroup$
            They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
            $endgroup$
            – Ross Millikan
            Jan 20 at 21:33


















          0












          $begingroup$

          It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)ldots (a-9)b(b-1)(b-2)(b-4)ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
            $endgroup$
            – msj
            Jan 20 at 21:23










          • $begingroup$
            They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
            $endgroup$
            – Ross Millikan
            Jan 20 at 21:33
















          0












          0








          0





          $begingroup$

          It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)ldots (a-9)b(b-1)(b-2)(b-4)ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.






          share|cite|improve this answer









          $endgroup$



          It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)ldots (a-9)b(b-1)(b-2)(b-4)ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Jan 20 at 20:24









          Ross MillikanRoss Millikan

          298k24200373




          298k24200373












          • $begingroup$
            Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
            $endgroup$
            – msj
            Jan 20 at 21:23










          • $begingroup$
            They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
            $endgroup$
            – Ross Millikan
            Jan 20 at 21:33




















          • $begingroup$
            Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
            $endgroup$
            – msj
            Jan 20 at 21:23










          • $begingroup$
            They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
            $endgroup$
            – Ross Millikan
            Jan 20 at 21:33


















          $begingroup$
          Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
          $endgroup$
          – msj
          Jan 20 at 21:23




          $begingroup$
          Good idea, but this leads to real coefficients. I can only use integer coefficients or powers of 2 and 10 (positive or negative). Do you have any more idea what we can do?
          $endgroup$
          – msj
          Jan 20 at 21:23












          $begingroup$
          They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
          $endgroup$
          – Ross Millikan
          Jan 20 at 21:33






          $begingroup$
          They are rational, so you can store them as numerator and denominator. They will be around $9!^2$ so too large for $32$ bit integers
          $endgroup$
          – Ross Millikan
          Jan 20 at 21:33




















          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%2f3081088%2fclosed-form-addition-of-bcd-numbers%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

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

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

          WPF add header to Image with URL pettitions [duplicate]