converts hexidecimal values to decimal


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: converts hexidecimal values to decimal

  1. #1
    Join Date
    Dec 2005
    Posts
    8

    converts hexidecimal values to decimal

    Can someone show me in java code how an application can read a string as its a hexdecimal number and converts hexidecimal values to decimal

    than you

  2. #2
    Join Date
    Dec 2005
    Posts
    7
    Code:
    		String hex = "E0DA453";
    		String temp = "";
    		char ch = ' ';
    		int dec = 0;
    		int val = 0;
    		int cnt = 0;
    		for(int i = hex.length()-1; i >=0 ; i--)
    		{
    			ch = hex.charAt(i);
    			if(ch == 'A')val = 10;
    			else if(ch == 'B') val = 11;
    			else if(ch == 'C') val = 12;
    			else if(ch == 'D') val = 13;
    			else if(ch == 'E') val = 14;
    			else if(ch == 'F') val = 15;
    			else
    			{
    				temp+=ch;
    				val = Integer.parseInt(temp);
    			}
    			dec += (val * Math.pow(16, cnt));
    			temp = "";
    			cnt++;
    		}
    something like this works...doubtful that it is the most efficient way, just something i threw together real quick...

    note: the string variable hex at the top is what is being changed...u could make that so it is read in so you could use it as a converter and just convert numbers that a user inputs...

    hope that helps at least a little...

  3. #3
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    In tips section of DevX..

    http://www.devx.com/tips/Tip/20752

  4. #4
    Join Date
    Dec 2005
    Posts
    8
    thxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx al0o0o0o0o0ot that was so helpful

  5. #5
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    No problem.. Anytime

Similar Threads

  1. Replies: 2
    Last Post: 09-27-2006, 07:29 PM
  2. How to tell decimal values from integer values?
    By Michael Tzoanos in forum Database
    Replies: 2
    Last Post: 04-11-2002, 03:30 PM
  3. Conversion of decimal in Oracle to Access 2000
    By Villy Olsson in forum Database
    Replies: 4
    Last Post: 04-06-2002, 08:01 PM
  4. Replies: 0
    Last Post: 02-25-2001, 12:58 PM
  5. losing Form values from option boxes
    By Paul Klanderud in forum ASP.NET
    Replies: 2
    Last Post: 07-26-2000, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center