{"id":7037,"date":"2025-06-28T00:01:26","date_gmt":"2025-06-28T07:01:26","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7037"},"modified":"2025-07-05T09:43:17","modified_gmt":"2025-07-05T16:43:17","slug":"base-36","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7037","title":{"rendered":"Base 36"},"content":{"rendered":"<p>This month&#8217;s <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6987\">Exercise<\/a> output values in various bases, but only those bases from 2 to 10. For other bases, especially those that alien beings might use, more effort is required. Therefore, I&#8217;d like to begin exploring a ridiculous counting base, base 36.<br \/>\n<!--more--><br \/>\nI tried to devise a clever name for base 36. I wanted to call it <em>yardle<\/em> because 36 inches are in a yard, but this word is already used in various capacities. So, my efforts are expressed as &#8220;base 36.&#8221; Boring.<\/p>\n<p>Base 36 builds on the technique used in Hexadecimal, base 16. To express values 11 through 15 as single digits, letters A through F are used:<\/p>\n<p><code>0 1 2 3 4 5 6 7 8 9 A B C D E F<\/code><\/p>\n<p>To represent 36 values in a single digit, I continue this pattern on up to letter Z:<\/p>\n<p><code>0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z<\/code><\/p>\n<p>These characters allow for values up to 36 in each position, which makes for larger numbers to be expressed with fewer digits. It also allows for the <em>base<\/em> program I wrote to be updated to convert values into any base from 2 up to 36. But this type of conversion must happen one step at a time.<\/p>\n<p>The first step is to write a function that outputs a value in base 36. I&#8217;m starting small, using only values in the range of zero through 35. In fact, for this code and for future lessons, I&#8217;ve set the constant <code>BASE36_MAX<\/code> equal to 36. Here&#8217;s the code:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2025_06_28-Lesson.c\" rel=\"noopener\" target=\"_blank\">2025_06_28-Lesson.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\n#define BASE36_MAX 36\r\n\r\n<span class=\"comments\">\/* output a base 36 value *\/<\/span>\r\nchar base36_output(int v)\r\n{\r\n    if( v&lt;10 )\r\n        return( v+'0' );\r\n    else if( v&lt;BASE36_MAX )\r\n        return( v+'A'-10 );\r\n    else\r\n        return('\\0');\r\n}\r\n\r\nint main()\r\n{\r\n    int x;\r\n\r\n    puts(\"Decimal - Base 36\");\r\n    for( x=0; x&lt;BASE36_MAX; x++ )\r\n        printf(\"%2d\\t%c\\n\",x,base36_output(x) );\r\n\r\n    return 0;\r\n}<\/pre>\n<p>The <em>base36_output()<\/em> function accepts a value, <code>v<\/code>. This value is converted into the base 36 character, 0 through Z, and the character is returned. Invalid input returns the null character.<\/p>\n<p>The <em>main()<\/em> function calls <em>base36_output()<\/em> 36 times, displaying the decimal and base 36 equivalents as output:<\/p>\n<p><code>Decimal&nbsp;-&nbsp;Base&nbsp;36<br \/>\n&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br \/>\n&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<br \/>\n&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<br \/>\n&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<br \/>\n&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4<br \/>\n&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5<br \/>\n&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6<br \/>\n&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7<br \/>\n&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8<br \/>\n&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9<br \/>\n10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A<br \/>\n11&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp;&nbsp;Y<br \/>\n35&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Z<\/code><\/p>\n<p>The next step in this program&#8217;s evolution is to express larger values in base 36 notation. This improvement to the code is presented starting with <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7043\">next week&#8217;s Lesson<\/a>. Then, providing that I can get everything to work, future Lessons play with base 36 math. Fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Binary, Octal, Decimal, Hexadecimal, and now . . . Base 36! <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7037\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7037","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7037"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7037\/revisions"}],"predecessor-version":[{"id":7063,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7037\/revisions\/7063"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}