ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » I'm not getting the desired output after converting

Post new topic  Reply to topic
 I'm not getting the desired output after converting « View previous topic :: View next topic » 
Author Message
WatsonGeorge
PostPosted: Wed Nov 22, 2017 12:21 am    Post subject: I'm not getting the desired output after converting Reply with quote

Guest




I executed the code below in my Eclipse. After execution i'm not getting the desired output.

Code:
import java.util.Scanner;

public class HexaToDecimal
{
   public static int convertHexadecimal(String str)
    {
      String strHexa = "0123456789ABCDEF";
      str = str.toUpperCase();
      int temp = 0;
      for (int a = 0; a < str.length(); a++)
      {
         char h = str.charAt(a);
         int d = strHexa.indexOf(h);
         temp = 16 * temp + d;
      }
      return temp;
    }
   
   public static void main(String[] args)
   {
      String strHexdecimal;
        int decimalNumber;
        Scanner sc = new Scanner(System.in);
        System.out.print("Please enter hexadecimal number : ");
        strHexdecimal = sc.nextLine();
        decimalNumber = convertHexadecimal(strHexdecimal);
        System.out.print("The decimal number is " + strHexdecimal);
        sc.close();
   }
}



Correct me!!
Back to top
WatsonGeorge
PostPosted: Wed Nov 22, 2017 12:24 am    Post subject: Reply with quote

Guest




Here's the solution - http://www.flowerbrackets.com/java-program-to-convert-hexadecimal-to-decimal/
Back to top
fjb_saper
PostPosted: Wed Nov 22, 2017 6:44 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

WatsonGeorge wrote:
Here's the solution - http://www.flowerbrackets.com/java-program-to-convert-hexadecimal-to-decimal/

This may be working fine for numbers. Think of it however just as an incentive to code your own when moving from a byte[] to hex text and vice versa...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » I'm not getting the desired output after converting
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.