<script type="text/javascript">
    function StringToNumberArray(Bin) {
            var numberArray = [];
            for (var i = 0; i < Bin.length; i++) {
                numberArray.push(Bin.substring(i, i + 1));
            }
            return numberArray;
        }
    
    function ConvertToDecimal(Bin)
    {
         Bin = StringToNumberArray(Bin);
          var dec = 0;
          var MASK;
          for(var i=0; i< Bin.length; i++)
          {
            dec <<= 1;
           
            switch(Bin[i])
            {
                case '0' :
                MASK =0;
                break;
                case '1' :
                MASK =1;
                break;
                default:
                alert("not binary");
                break;
                
            }
            dec |= MASK;
          }
          return dec;
       
    }
  
       // example usage :
       // ConvertToDecimal("1010");
    </script>
1
Contributor
0
Replies
1
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.