Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="texts">
  <h2>Number Systems</h2>
  <p>The below visualization shows a counter with Decimal, HexaDecimal and Binary number systems. You can click on the "+" or "-" button to increase / decrease the counter and see how all these three numbering system works. There is also a table to explain these numbering systems.</p>
</div>

<div class="content">
  <label>Decimal</label>
  <div class="counter">
    <div><div id="dec_9">0</div></div>
    <div><div id="dec_8">0</div></div>
    <div><div id="dec_7">0</div></div>
    <div><div id="dec_6">0</div></div>
    <div><div id="dec_5">0</div></div>
    <div><div id="dec_4">0</div></div>
    <div><div id="dec_3">0</div></div>
    <div><div id="dec_2">0</div></div>
    <div><div id="dec_1">0</div></div>
    <div><div id="dec_0">0</div></div>
  </div>
</div>

<div class="content">
  <label>Hexadecimal</label>
  <div class="counter">
    <div><div id="hex_9">0</div></div>
    <div><div id="hex_8">0</div></div>
    <div><div id="hex_7">0</div></div>
    <div><div id="hex_6">0</div></div>
    <div><div id="hex_5">0</div></div>
    <div><div id="hex_4">0</div></div>
    <div><div id="hex_3">0</div></div>
    <div><div id="hex_2">0</div></div>
    <div><div id="hex_1">0</div></div>
    <div><div id="hex_0">0</div></div>

  </div>
</div>

<div class="content">
  <label>Binary</label>
  <div class="counter">
    <div><div id="bin_9">0</div></div>
    <div><div id="bin_8">0</div></div>
    <div><div id="bin_7">0</div></div>
    <div><div id="bin_6">0</div></div>
    <div><div id="bin_5">0</div></div>
    <div><div id="bin_4">0</div></div>
    <div><div id="bin_3">0</div></div>
    <div><div id="bin_2">0</div></div>
    <div><div id="bin_1">0</div></div>
    <div><div id="bin_0">0</div></div>
  </div>
</div>

<div class="actions">
  <a class="noselect" id="increase">+</a>
  <a class="noselect" id="decrease">&ndash;</a>
</div>

<div class="table">
  
  <div class="tcol" id="col_dec">
    <div class="thead">
      Decimal<br/>
      <em>(base 10)</em>
    </div>
  </div>
  
  <div class="tcol" id="col_hex">
    <div class="thead">
      HexaDecimal<br/>
      <em>(base 16)</em>
    </div>
  </div>
  
  <div class="tcol" id="col_bin">
    <div class="thead">
      Binary<br/>
      <em>(base 2)</em>
    </div>
  </div>
</div>

<div class="texts">
  <h2>Usage of Different numbering systems</h2>
  
  <h3>Decimal</h3>
  <p>The most popular decimal numbering system is what we use in our daily life. It uses 10 unique digits ( 0,1,2,3,4,5,6,7,8,9). And it has a base of 10, which means that everytime we move left one digit, the value is 10 time bigger.</p>
  
  
  <h3>HexaDecimal</h3>
  <p>It is very popular in computer design and graphics, and colors. It uses 16 unique digits (0,1,2,3,4,5,6,7,8,9, A,B,C,D,E,F). And it has a base of 16.</p>
    
   <p>In mostly all graphics program including HTML and CSS langage, colors are represented in Hexadecimal numbers. You can refer this link to know more in detail: </p>
  <a href="https://www.mathsisfun.com/hexadecimal-decimal-colors.html">https://www.mathsisfun.com/hexadecimal-decimal-colors.html</a>
  
  
  
  
  
  <h3>Binary</h3>
  <p>Binary number system is uses only two digits 0 and 1. Please read the below article to understand more:</p>
  
 <a href="https://www.mathsisfun.com/binary-number-system.html">https://www.mathsisfun.com/binary-number-system.html</a>
  
</div>
              
            
!

CSS

              
                *, *::before, *::after {
  box-sizing: border-box;
}

p {
  line-height: 1.5em;
}

body {
  padding: 10px 0 50px;
  color: #000;
  font-family: sans-serif;
  background-color: #222831;
  max-width: 560px;
  margin:0 auto;
  display:grid;
  column-gap:20px;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto auto;
}

.texts{
  grid-column: 1/-1;
  color: #E1E3E7;
}
.texts h2{
  text-align: center;
  border-bottom: 1px solid #ccc;
  padding-bottom:20px;
}

.texts a {
  color: white;
  text-decoration: none;
  border-bottom: 1px dashed lime;
}

label{
  color: #E1E3E7;
  padding:0 10px;
}
.content {
  flex-basis:400px;
  display:flex;
  align-items: center;
  justify-content:flex-end;
  grid-column:1/2;
}

.counter{
  display:flex;
  margin:10px 0;
  border: 1px solid #666;
  background-color: #ddd;
}

.counter > div {
  overflow: hidden;
  position: relative;
  font-weight: bold;
  font-size:1.2em;
  display:flex;
  align-items: center;
  justify-content:center;
  background-color: white;
  width: 35px;
  height: 35px;
  margin: 1px;
  border: 1px solid #666;
  box-shadow:0px 0px 5px rgba(0,0,0,0.8) inset;
}


.slide_up_out {animation: slideupout 500ms linear forwards;}
@keyframes slideupout {
  from {transform:translateY(0px);}
  to {transform:translateY(-30px);}
}

.slide_up_in {animation: slideupin 500ms linear forwards;}
@keyframes slideupin {
  from {transform:translateY(30px);}
  to {transform:translateY(0px);}
}


.actions{
  grid-column: 2/3;
  grid-row:2/5;
  display:flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}
#increase, #decrease {
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  background-color: #E1E3E7;
  font-size:2em;
  display:block;
  width: 50px;
  padding: 8px 0;
}

#increase {
  border-top-left-radius:50%;
  border-top-right-radius:50%;
}
#decrease {
  border-top: 1px solid #999;
  border-bottom-left-radius:50%;
  border-bottom-right-radius:50%;
}

#increase:active, #decrease:active{
  box-shadow:0px 0px 2px rgba(0,0,0,0.8) inset;
}

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Old versions of Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
}


.table {
  margin-top:20px;
  grid-column: 1/-1;
  background-color: #E1E3E7;
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  justify-content: center;
  text-align:right;
  max-height: 300px;
  overflow-y: scroll;
}

.tcol {
  border-left: 1px solid #ddd;
  position:relative;
}
.tcol > div {
  border-top: 1px solid #ccc;
  padding:5px 10px 4px;
}

em{font-weight: 300;
font-size:0.8em}



.thead {
  position:sticky;
  top:0;
  background-color:#fff;
  font-size: 1.1em;
  font-weight: bold;
  box-shadow: 0px 0px 3px rgba(0,0,0,0.5);
}
              
            
!

JS

              
                var x = 0;
btnIncrease = document.querySelector("#increase");
btnDecrease = document.querySelector("#decrease");

col_dec = document.querySelector("#col_dec");
col_hex = document.querySelector("#col_hex");
col_bin = document.querySelector("#col_bin");


function replaceText(id, textArr){
  for(i=0; i<numArr.length;i++){
    elem = document.querySelector(id + i)
    if(elem.innerHTML != textArr[i])
      elem.innerHTML = textArr[i];
  }
}


function updateDec(){
  numArr = x.toString().padStart(9, '0').split('').reverse();
  replaceText("#dec_", numArr);
}

function updateHex(){
  numArr = x.toString(16).toUpperCase().padStart(9, '0').split('').reverse();
  replaceText("#hex_", numArr);
}

function updateBin(){
  numArr = x.toString(2).padStart(9, '0').split('').reverse();
  replaceText("#bin_", numArr);
}


function update(){
  updateDec();
  updateHex();
  updateBin();
}

function printTableBin(){
  for(i=0; i<51; i++){
    
    var newDiv = document.createElement("div")
    newDiv.innerHTML = i
    col_dec.appendChild(newDiv);
    
    var newDiv = document.createElement("div")
    newDiv.innerHTML = i.toString(16).toUpperCase();
    col_hex.appendChild(newDiv);
    
    var newDiv = document.createElement("div")
    newDiv.innerHTML = i.toString(2);
    col_bin.appendChild(newDiv);
    
  }
}


printTableBin();

btnIncrease.onclick = function(){
  x = x+1;
  update();
}
btnDecrease.onclick = function(){
  if(x>0) x = x-1;
  update();
}









              
            
!
999px

Console