Use the parseInt Function with a Radix

This is the same as the parseint function, but you can also specify a base for the number which can be between 2 - 36. 2 is binary. Zeros and Ones. I think base 10 is the normal numbering system, but thats just a guess. ;) I'll test it. 3 is an integer.

Demo

function using_parseint_radix(maybe_an_int, radix = 2) {
  var result_html = document.getElementById("result");
  var parseint_result = parseInt(maybe_an_int, radix);
  result_html.innerHTML = parseint_result;
  return parseint_result;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='using_parseint_radix("0000", "2");' class='btn btn-primary mb-1'>Binary Conversion of 0000</button>
<button onclick='using_parseint_radix("1235", "2");' class='btn btn-primary mb-1'>Binary Conversion of 1235</button>
<button onclick='using_parseint_radix("00001235", "10");' class='btn btn-primary mb-1'>Base 10 Conversion of 00001235</button>

Result

..

External Link for Use the parseInt Function with a Radix

Other Items in javascript
Page Views

This page has been viewed 68 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹