<!DOCTYPE html> <html lang="en"> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> </div> </nav> <div class="col-md-6 well"> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-6"> <div class="form-group"> <input type = "number" id="binary" class="form-control"/> </div> </div> </div> </body> </html>
function binaryToDecimal() { var binary = document.getElementById("binary").value; if(binary == ""){ alert("Please fill up the required field!"); }else{ if(/^[01]+$/.test(binary)){ var decimal = parseInt(binary, 2); document.getElementById("result").innerHTML = "<center><label style='font-size:18px;'>The decimal number is</label></center><center><h3 class='text-primary'>"+decimal+"</h3></center>"; }else{ alert("Please enter binary numbers"); } } } function reset(){ document.getElementById("decimal").value = ""; document.getElementById("result").innerHTML = ""; }