{"id":51,"date":"2021-09-14T02:59:38","date_gmt":"2021-09-14T02:59:38","guid":{"rendered":"http:\/\/thorshov.net\/?p=51"},"modified":"2021-12-10T18:34:33","modified_gmt":"2021-12-10T18:34:33","slug":"recursive-radix-calculations","status":"publish","type":"post","link":"https:\/\/thorshov.net\/index.php\/2021\/09\/14\/recursive-radix-calculations\/","title":{"rendered":"Recursive Radix Calculations"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">My daughter and I share a special number - 823.  We text it to eachother when the clock says 8:23 or leave a little note with it there.  We also share other instances of the number that we come accross. I sent these photos to her recently:<\/pre>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-medium\"><img loading=\"lazy\" width=\"300\" height=\"146\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-300x146.jpg\" alt=\"\" class=\"wp-image-75\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-300x146.jpg 300w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-1024x498.jpg 1024w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-768x373.jpg 768w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-1536x747.jpg 1536w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-2048x996.jpg 2048w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/20210512_102048-1568x762.jpg 1568w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption>The address is 823<\/figcaption><\/figure><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-medium is-resized\"><img loading=\"lazy\" src=\"https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/823_1-264x300.jpg\" alt=\"\" class=\"wp-image-76\" width=\"132\" height=\"150\" srcset=\"https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/823_1-264x300.jpg 264w, https:\/\/thorshov.net\/wp-content\/uploads\/2021\/09\/823_1.jpg 654w\" sizes=\"(max-width: 132px) 100vw, 132px\" \/><figcaption>823 in Binary  1100110111<\/figcaption><\/figure><\/div>\n<\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">It's a nice way to let each other know that we are thinking about one another.  Lately, I was wondering what 823 looked like in other bases besides decimal(10) and binary(2). So I wrote a recursive javascript function called convert to do the job.  The user can enter a decimal number and new base to see the equivelant value with the new radix.<\/pre>\n\n\n\n<pre title=\"Recursive Radix Calculation\" class=\"wp-block-code scottclass\"><code lang=\"markup\" class=\"language-markup\">&lt;!DOCTYPE HTML&gt;\n&lt;html&gt;\n&lt;script&gt;\n   function doit(){\n      var decimal = parseInt(document.getElementById('decimal').value);\n      var newBase = parseInt(document.getElementById('newBase').value);\n      var output = document.getElementById('output');\n      if(newBase &gt; 1 &amp;&amp; newBase &lt;10)      \n         output.innerHTML = convert(decimal, newBase);\n   }\n   \n   function convert(quotient, base){\n      if(quotient &gt; 0){\n        var remainder = quotient % base;\n        return convert(parseInt(quotient \/ base), base) + remainder.toString();\n      }\n      return '';\n   }\n&lt;\/script&gt;\n&lt;body&gt;\n    Decimal: &lt;input type=\"text\" id=\"decimal\"&gt;\n    New Base:   &lt;input type=\"text\" id=\"newBase\"&gt;\n    &lt;button type=\"button\" label=\"doit\" onclick=\"doit();\"&gt;do it&lt;\/button&gt;\n    &lt;div id=\"output\"&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">And here is the result.  You can enter a decimal number and a base between 2 and 9 inclusively. <\/pre>\n\n\n\n<script>\n   function doit(){\n      var decimal = parseInt(document.getElementById('decimal').value);\n      var newBase = parseInt(document.getElementById('newBase').value);\n      var output = document.getElementById('output');\n      if(newBase > 1 && newBase <10)      \n         output.innerHTML = convert(decimal, newBase);\n   }\n   \n   function convert(quotient, base){\n      if(quotient > 0){\n        var remainder = quotient % base;\n        return convert(parseInt(quotient \/ base), base) + remainder.toString();\n      }\n      return '';\n   }\n<\/script>\n    Decimal: <input type=\"text\" id=\"decimal\">\n    New Base:   <input type=\"text\" id=\"newBase\">\n    <button type=\"button\" label=\"doit\" onclick=\"doit();\">do it<\/button>\n    <div id=\"output\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>My daughter and I share a special number &#8211; 823. We text it to eachother when the clock says 8:23 or leave a little note with it there. We also share other instances of the number that we come accross. I sent these photos to her recently: It&#8217;s a nice way to let each other &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thorshov.net\/index.php\/2021\/09\/14\/recursive-radix-calculations\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Recursive Radix Calculations&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":76,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,5],"tags":[],"_links":{"self":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/51"}],"collection":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":22,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions\/117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/media\/76"}],"wp:attachment":[{"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thorshov.net\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}