java - Converting Hexadecimal to Decimal Without .parseInt(); -


I am writing some code that works in hexadecimal with no built-in Java functions such as integer within decimal 16);

This is what I have created, and it does not work:

  public static hexdomackel (string heximput) {string hexine = hexinput. "," ") .tem (); scanner hex = new scanner (hex in); int decimals = 0; int power = 1; while (hex haas (next () == true) {string temp = hex.xx ( ); If (temp.equals ("1") == true) {decimal + = 1 * power;} and if (temp.equals ("2") == true) {decimal + = 2 * power;} and If (temp.equals ("3") == true) {decimal + = 3 * power;} and if (temp.equals ("4") == true) {decimal + = 4 * power;} and if ( Temp.equals ("5") == true) {decimal + = 5 * power;} and if (temp.equals ("6") == true) {decimal + = 6 * power;} and if (temp. Equals ("7") == true) {decimal + = 7 * power;} and if (temp.equals ("8") == true) { (Decimal = = 9 * power;} and if (temp.equals ("A") == true) {decimal + = 10 * power;} and if (temp.equals ("B") == true) {decimal + = 11 * power;} and if (temp.equals ("C") == true) {decimal + = 12 * Power;} and if (temp.equals ("D") == true) {decimal + = 13 * power;} and if (temp.equals ("e") == true) {decimal + = 14 * power ;} And if (temp.equals ("F") == true) {decimal + = 15 * power; } Electricity = electricity * 16; } System.out.println (decimal); Return decimals; }  

Can I get some help? It seems that there is some basic functionality in it, but it breaks with most inputs thanks for the help!

As you scan to the right, you're multiplying 16 by progressively higher powers. In fact, unlike what you want. Instead try this argument, which is a bit easier than what you are now doing:

  public static hexdomackel (string heximput) {int decimal = 0; Int len ​​= hexInput.length (); For (int i = 0; i  

It now scans from left to right, which is now doing, multiplying the properties of the value already processed by 16 for each new hex digit.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -