{"id":6987,"date":"2025-06-01T00:01:58","date_gmt":"2025-06-01T07:01:58","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6987"},"modified":"2025-06-08T17:03:26","modified_gmt":"2025-06-09T00:03:26","slug":"pick-the-base","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6987","title":{"rendered":"Pick the Base"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9734;<\/h2>\n<p>I watched the film <em>Contact<\/em> a few weeks ago. The movie is about first contact with an alien civilization. It&#8217;s smart cinema, which offers that communications between species would be mathematical in nature, as math is the universal language.<br \/>\n<!--more--><br \/>\nThe topic of math as a language isn&#8217;t explored deeply in the picture, mostly because the filmmakers want the audience to stay awake. But recently during a pre-sleep moment, I wondered about math as a universal language. Yes, we could communicate with high-intelligent aliens by sending out prime numbers. But in what base?<\/p>\n<p>In the film, the aliens transmit prime numbers as a series of pulses. Beyond this math, the other math in the film isn&#8217;t explained, though from screenshots it looks binary in nature. The puzzle I pondered was whether humans would assume that all intelligent species use base 10 decimal?<\/p>\n<p>As a future employee of <a href=\"https:\/\/www.seti.org\/\" target=\"_blank\">SETI<\/a>, it&#8217;s your job to code a program that translates values from base 10 into another base. Don&#8217;t worry about communicating with aliens, this challenge is just pretend. In fact, I&#8217;m going to limit the bases from two to ten.<\/p>\n<p>The program prompts for a base and then a value in decimal. The output shows the value as it appears in the other base. For example:<\/p>\n<p><code>Enter base (>1 <11): 5\nEnter value (>1): 12345<br \/>\n12345 in base 5 is 343340<\/code><\/p>\n<p>The value 12,345 in base 5 is written as 343,340.<\/p>\n<p>Here&#8217;s another run:<\/p>\n<p><code>Enter base (>1 <11): 2\nEnter value (>1): 85<br \/>\n85 in base 2 is 1010101<\/code><\/p>\n<p>Your task is to write this program, perhaps not for SETI but as this month&#8217;s exercise.<\/p>\n<p>As a bit of help, five years ago I wrote a <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4212\">post<\/a> on outputting values in any base. But one of the keys for this exercise is for the result not to contain any leading zeros, as you see in the output above from my solution.<\/p>\n<p>Try this exercise on your own before you check out <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7006\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Computers work in binary but can output values in any base. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6987\">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":[3],"tags":[],"class_list":["post-6987","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6987","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=6987"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6987\/revisions"}],"predecessor-version":[{"id":7033,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6987\/revisions\/7033"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}