Hexadecimal to decimal converter in JS

It’s been one year since I am working on an IOT app and finally the project is going to finish. But still, this project is giving me headaches in different ways.

Just recently, my client wanted me to develop a hexadecimal to decimal converter. I was r…


This content originally appeared on DEV Community and was authored by Mallaya

It's been one year since I am working on an IOT app and finally the project is going to finish. But still, this project is giving me headaches in different ways.

Just recently, my client wanted me to develop a hexadecimal to decimal converter. I was really bad at these conversions during my school. I used to use the online tools for such conversions and now I had to develop such hexadecimal to decimal tool. So, I did research and study for a day and then started developing it.

I thought it would be great if I share the Javascript code here to develop a hex to the decimal tool then it would be beneficial for those working on such converters.

  function hexadecimaltodecimal() {
      var input_number = document.getElementById("input_value").value;
      var initialconversion = new BigNumber(input_number , 16);
      var finalanswer = initialconversion.toString(10);
      document.getElementById("ans").innerHTML = finalanswer;
     }

In this article, we have used the bignumber.js javascript library that deals with big numbers. If you don't use the library, you might not get the correct answer for large numbers. Copy the following code and paste it into the head tag for bignumber.js.

<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/8.0.2/bignumber.min.js" integrity="sha512-7UzDjRNKHpQnkh1Wf1l6i/OPINS9P2DDzTwQNX79JxfbInCXGpgI1RPb3ZD+uTP3O5X7Ke4e0+cxt2TxV7n0qQ==" crossorigin="anonymous"></script>


This content originally appeared on DEV Community and was authored by Mallaya


Print Share Comment Cite Upload Translate Updates
APA

Mallaya | Sciencx (2022-02-08T06:28:28+00:00) Hexadecimal to decimal converter in JS. Retrieved from https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/

MLA
" » Hexadecimal to decimal converter in JS." Mallaya | Sciencx - Tuesday February 8, 2022, https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/
HARVARD
Mallaya | Sciencx Tuesday February 8, 2022 » Hexadecimal to decimal converter in JS., viewed ,<https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/>
VANCOUVER
Mallaya | Sciencx - » Hexadecimal to decimal converter in JS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/
CHICAGO
" » Hexadecimal to decimal converter in JS." Mallaya | Sciencx - Accessed . https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/
IEEE
" » Hexadecimal to decimal converter in JS." Mallaya | Sciencx [Online]. Available: https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/. [Accessed: ]
rf:citation
» Hexadecimal to decimal converter in JS | Mallaya | Sciencx | https://www.scien.cx/2022/02/08/hexadecimal-to-decimal-converter-in-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.