{"id":690,"date":"2020-04-12T13:54:20","date_gmt":"2020-04-12T13:54:20","guid":{"rendered":"https:\/\/computerscienced.co.uk\/site\/?page_id=690"},"modified":"2022-01-11T22:28:07","modified_gmt":"2022-01-11T22:28:07","slug":"binary-to-denary-test-8-digits","status":"publish","type":"page","link":"https:\/\/computerscienced.co.uk\/site\/binary\/binary-to-denary\/binary-to-denary-test-8-digits\/","title":{"rendered":"Binary to denary test &#8211; 8 digits"},"content":{"rendered":"\n<body onload=\"displaybinary()\">\n<style>\n#myDIV {\n  width: 100%;\n  padding: 5px 0;\n  text-align: left;\n  background-color: green;\n  color: white;\n  margin-top: 5px;\ndisplay: none;\n}\n#myDIVwrong {\n  width: 100%;\n  padding: 5px 0;\n  text-align: left;\n  background-color: red;\n  color: white;\n  margin-top: 5px;\ndisplay: none;\n}\n#myDIVhelp {\n  width: 100%;\n  padding: 5px 0;\n  text-align: left;\n  background-color: #0073aa;\n  color: white;\n  margin-top: 5px;\ndisplay: none;\n}\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{font-family:Arial, sans-serif;font-size:18px;padding:20px 20px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg th{font-family:Arial, sans-serif;font-size:18px;font-weight:normal;padding:20px 20px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg .tg-1wig{font-weight:bold;background-color:#9b9b9b;text-align:left;vertical-align:top}\n.tg .tg-0lax{text-align:left;vertical-align:top}\n<\/style>\n<script>\nfunction myFunction() {\nvar userInput = document.getElementById(\"textInput\").value;  \ntotal = (binary1*128) + (binary2*64) + (binary3*32) + (binary4*16) + (binary5*8) + (binary6*4) + (binary7*2) + (binary8*1);\nif (userInput == total) {\n  var x = document.getElementById(\"myDIV\");\n  if (x.style.display === \"block\") {\n    x.style.display = \"none\";\n  } else {\n    x.style.display = \"block\";\n  }\nanswer()\n}else {\nvar y = document.getElementById(\"myDIVwrong\");\n  if (y.style.display === \"block\") {\n    y.style.display = \"none\";\n  } else {\n    y.style.display = \"block\";\n  }\nanswer()\n}\n}\nfunction displaybinary() {\nvar x = document.getElementById(\"myDIV\");\n    x.style.display = \"none\";\nvar y = document.getElementById(\"myDIVwrong\");\n    y.style.display = \"none\";\nvar z = document.getElementById(\"myDIVhelp\");\n    z.style.display = \"none\";\n\nbinary1 = Math.floor(Math.random() * 2);\nbinary2 = Math.floor(Math.random() * 2);\nbinary3 = Math.floor(Math.random() * 2);\nbinary4 = Math.floor(Math.random() * 2);\nbinary5 = Math.floor(Math.random() * 2);\nbinary6 = Math.floor(Math.random() * 2);\nbinary7 = Math.floor(Math.random() * 2);\nbinary8 = Math.floor(Math.random() * 2);\ndocument.getElementById(\"myText\").innerHTML = binary1 +\"\"+ binary2+\"\"+ binary3+\"\"+ binary4+\"\"+ binary5+\"\"+ binary6+\"\"+ binary7+\"\"+ binary8;\n}\nfunction answer() {\ntotal = (binary1*128) + (binary2*64) + (binary3*32) + (binary4*16) + (binary5*8) + (binary6*4) + (binary7*2) + (binary8*1);\ndocument.getElementById(\"answerdisplay\").innerHTML = total;\ndocument.getElementById(\"answerdisplay2\").innerHTML = total;\n}\nfunction help() {\nvar z = document.getElementById(\"myDIVhelp\");\n  if (z.style.display === \"block\") {\n    z.style.display = \"none\";\n  } else {\n    z.style.display = \"block\";\n  }\n}\n<\/script>\n<div id=\"myDIVhelp\" onclick=\"help()\">\n<h2>How do I convert 8 digit binary to denary?<\/h2>\nTo convert binary numbers to denary (sometimes referred to as decimal) we simply use a table like the one below:<br\/>\n<table border=\"1\" class=\"tg\">\n  <tr>\n    <th class=\"tg-1wig\">  128  <\/th>\n    <th class=\"tg-1wig\">  64  <\/th>\n    <th class=\"tg-1wig\">  32  <\/th>    \n    <th class=\"tg-1wig\">  16  <\/th>\n    <th class=\"tg-1wig\">  8  <\/th>\n    <th class=\"tg-1wig\">  4  <\/th>\n    <th class=\"tg-1wig\">  2  <\/th>\n    <th class=\"tg-1wig\">  1  <\/th>\n  <\/tr>\n  <tr>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n    <td class=\"tg-0lax\">_<\/td>\n  <\/tr>\n<\/table>\n<p>The numbers on the top row always stay the same.  We simply take the binary number we have been given and put it in the row below the numbers.<\/p>\n<p><b>Example<\/b><\/p>\nConvert the number 00110011 into denary.<br\/>\nFirst we put our binary number into the bottom row of our table.<br\/>\n<table border=\"1\" class=\"tg\">\n  <tr>\n    <th class=\"tg-1wig\">  128  <\/th>\n    <th class=\"tg-1wig\">  64  <\/th>\n    <th class=\"tg-1wig\">  32  <\/th>    \n    <th class=\"tg-1wig\">  16  <\/th>\n    <th class=\"tg-1wig\">  8  <\/th>\n    <th class=\"tg-1wig\">  4  <\/th>\n    <th class=\"tg-1wig\">  2  <\/th>\n    <th class=\"tg-1wig\">  1  <\/th>\n  <\/tr>\n  <tr>\n    <td class=\"tg-0lax\">0<\/td>\n    <td class=\"tg-0lax\">0<\/td>\n    <td class=\"tg-0lax\">1<\/td>\n    <td class=\"tg-0lax\">1<\/td>\n    <td class=\"tg-0lax\">0<\/td>\n    <td class=\"tg-0lax\">0<\/td>\n    <td class=\"tg-0lax\">1<\/td>\n    <td class=\"tg-0lax\">1<\/td>\n  <\/tr>\n<\/table>\n<p>We now go through each column starting from the left.<br\/> In our first column there is a 0. We do not need to do anything.<br\/>  In the second column there is a 0.  We do not need to do anything.<br\/>  In the third column there is a 1.  Anytime there is a 1 in a column we take the number from the top row in this case a 32 and store it so we can add it to other numbers later.<br\/>  In the fourth column there is also a 1. As there is a 1 in the bottom column we take the number from the top row which is a 16 and store it with the other number.<br\/>\nIn the fifth column there is a 0.  We do not need to do anything.<br\/>\nIn the sixth column there is a 0.  We do not need to do anything.<br\/>\nIn the seventh column there is a 1.  Anytime there is a 1 in a column we take the number from the top row in this case a 2 and store it so we can add it to other numbers later.<br\/>  In the fourth column there is also a 1. As there is a 1 in the bottom column we take the number from the top row which is a 1 and store it with the other number.<br\/>\n<\/p>\n\n<p>All the numbers we have stored we now add together to give us our denary number.  32 + 16 + 2 + 1 = 3.  0011 in binary is 51 in denary.<\/p> \n<\/div>\n<p>Convert the following 8 digit binary number to denary \/ decimal:<\/p>\n<h2><span id=\"myText\"><\/span><\/h2>\n<p>Enter your answer: <input type=\"text\" id=\"textInput\" \/><\/p>\n<button onclick=\"myFunction()\">Submit your answer<\/button>\n<button onclick=\"displaybinary()\">Click to test again<\/button>\n<button onclick=\"help()\">Help<\/button>\n<div id=\"myDIV\">\n<h3>That is right!<\/h3>\n<h4>The right answer is <span id=\"answerdisplay\"><\/span><\/h4>\n<\/div>\n<div id=\"myDIVwrong\">\n<h3>That is not correct<\/h3>\n<h4>The right answer is <span id=\"answerdisplay2\"><\/span><\/h4>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do I convert 8 digit binary to denary? To convert binary numbers to denary (sometimes referred to as decimal)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2740,"parent":859,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"disable_featured_image":true,"footnotes":""},"class_list":["post-690","page","type-page","status-publish","has-post-thumbnail","hentry"],"blog_post_layout_featured_media_urls":{"thumbnail":["https:\/\/computerscienced.co.uk\/site\/wp-content\/uploads\/2021\/10\/undraw_exams_g4ow-1.svg",150,150,true],"full":["https:\/\/computerscienced.co.uk\/site\/wp-content\/uploads\/2021\/10\/undraw_exams_g4ow-1.svg",982,803,false]},"categories_names":null,"comments_number":"0","_links":{"self":[{"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/pages\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/comments?post=690"}],"version-history":[{"count":5,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/pages\/690\/revisions"}],"predecessor-version":[{"id":1543,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/pages\/690\/revisions\/1543"}],"up":[{"embeddable":true,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/pages\/859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/media\/2740"}],"wp:attachment":[{"href":"https:\/\/computerscienced.co.uk\/site\/wp-json\/wp\/v2\/media?parent=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}