Java code to convert - Hex to Dec

I'ld like to convert an Integer or a String from hexadecimal format to a decimal format;
For example: 30 give 0; 50 give P and so on.
Can any one help me sending to me a java code that do it please?
Thanx a lot

This doesn't convert hex to decimal, but it does convert hex to the character representation, which is what it sounds like you want. At any rate, given "30" it will print "0" and given "50" it will print "P". Also, given "P" it will print "is invalid".
        try
            int in = Integer.parseInt(s, 16);
            Character ch = new Character((char)in); // should validate range here
            System.out.println("In: " + s + ", out: " + ch);
        catch (NumberFormatException e)
            System.out.println("In: " + s + " is invalid.");
        }

Similar Messages

  • Java Code to Convert GIF to BMP

    Hi,
    Could anyone please tell me the Java Code to convert the GIF image to BMP image.
    Thanks,
    Rathish

    Here is a sample code for reading an Excel file. It uses JExcel API:
    package com.quicklyjava;
    import jxl.*;
    import jxl.read.biff.BiffException;
    import java.io.File;
    import java.io.IOException;
    public class JavaExcelRead {
    * @param args
    public static void main(String[] args) {
    try {
    //Create a workbook object from the file at specified location.
    //Change the path of the file as per the location on your computer.
    Workbook wrk1 = Workbook.getWorkbook(new File("C:/test.xls"));
    //Obtain the reference to the first sheet in the workbook
    Sheet sheet1 = wrk1.getSheet(0);
    //Obtain reference to the Cell using getCell(int col, int row) method of sheet
    Cell colArow1 = sheet1.getCell(0, 0);
    Cell colBrow1 = sheet1.getCell(1, 0);
    Cell colArow2 = sheet1.getCell(0, 1);
    //Read the contents of the Cell using getContents() method, which will return
    //it as a String
    String str_colArow1 = colArow1.getContents();
    String str_colBrow1 = colBrow1.getContents();
    String str_colArow2 = colArow2.getContents();
    //Display the cell contents
    System.out.println("Contents of cell Col A Row 1: \""+str_colArow1 + "\"");
    System.out.println("Contents of cell Col B Row 1: \""+str_colBrow1 + "\"");
    System.out.println("Contents of cell Col A Row 2: \""+str_colArow2 + "\"");
    } catch (BiffException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    You can further process this to convert the data extracted into XML. Hope this helps!

  • Converting hex to dec

    Hi everybody,
    I want to join this two numbers and convert them from hex to dec. I have tried using joint and conversion but I still couldn't work it. In the following screen shot I took it suppose to be 3E8 in hex which equals to 1000 in dec. I need suggestion from you how to approach this.
    Thanks
    Solved!
    Go to Solution.

    SOBGA wrote:
    As I was reading all the answers about converting Hex to Dec,I found out that many of you are making it so complicated.To make it easier for a learner or beginner,this is what it takes:
    Open a blank VI
    Click on numeric control
    Right click on the same numeric control
    Scroll down to "Representation"
    Click on "U8"
    Go to numeric indicator and repeat step 4 and 5
    Then right click again on numeric control
    Scroll down to "Properties" and click
    Click on "Data entry",if necessary,change the minimum and maximum
    Pass to "Display format" 
    Click on "Hexadecimal" then you are done.The rest is to go on the block diagram to wire the numeric control to the numeric indicator and it works.
    You can do the same process reverse for dec to hex.But you must know that what we did for "numeric control" on (Hex to Dec) will be done to "numeric indicator" on (Dec to Hex).This same process can apply to octal and binary without the use of complicated array,string while loop and so on...
    I'm a beginner in Labview and I understand that you need to explain more to understand better.
    If you really read all of the comments, you would see that Altenbach already stated this (saying it is just a cosmetic property for the indicator).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Convert  Hex to Dec in Numbers

    Hi,
    Can some one let me know how to Convert Hex to Dec in Numbers.
    When ever I type Hex 00E0 it will appear in the cell like this 0.00E+00 ,who do i fix this.
    Thanks
    Ashan

    -+-+-+-+-+-+-+-
    Entering the Help and Terms of Use area you will read:
    *What is Apple Discussions and how can it help me?* 

    Apple Discussions is a user-to-user support forum where experts and other Apple product users get together to discuss Apple products. … You can participate in discussions about various products and topics, find solutions to help you resolve issues, ask questions, get tips and advice, and more.
    _If you have a technical question about an Apple product, be sure to check out Apple's support resources first by consulting the application Help menu on your computer and visiting our Support site to view articles and more on our product support pages_.
    I have a question or issue—how do I search for answers? _
It's possible that your question or issue has already been answered by other members so do a search before posting a question._ On most Apple Discussions pages, you'll find a Search Discussions box in the upper right corner. Enter a search term (or terms) in the field and press Return. Your results will appear as a list of links to posts below the Search Discussions Content pane.
    -+-+-+-+-+-+-+-
    Taking care of that, you would already know the response.
    Using the really cumbersome keystring "convert AND hex" as described in the forum's help returns two entries.
    One is you question.
    The other is: http://discussions.apple.com/thread.jspa?messageID=7242325
    which gives a link to:
    http://discussions.apple.com/thread.jspa?messageID=7078123
    Yvan KOENIG (from FRANCE jeudi 24 juillet 2008 09:19:34)

  • Java code for converting EDI file to XML file

    Dear friends,
                     Can you please help me in getting the java code for converting to EDI file to XML file.

    Hi,
    You can convert the EDI file to XML in any of the ways
    1) Using third party seeburger adapters
    2) Conversion agent
    3) Stylus studio.
    I think using java code it will be very difficult.
    Thnx
    Chirag

  • Java code to convert XML file to ISO XML format

    Hi Experts,
    I need to convert an XML file to ISO Xml format using Java code.I dont have any idea about the ISO XML format.I searched but what i am getting is ISO is an encoding in XML.
    It will be very helpful if any one can give me a sample ISO XML file, and any way around to carry out the required conversion.
    Thanks .
    Anika

    Hi,
    For ISO encoding you need the XML file to be converted with below providing the encoding paramter as ISO. for e.g.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    instead of
    <?xml version="1.0" encoding="UTF-8"?>
    this can be possible with using XML encoders.
    Refer XML encoding--> http://www.w3schools.com/XML/xml_encoding.asp
    Refer Java Code with uasage of XMLEncoder
    http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html
    Thanks
    Swarup

  • JAVA code to Convert Excel file To XML file

    Hi,
    I am new to java ,Any one please share me the code to convert Excel file in to xml file.
    Thanks in advance.

    Here is a sample code for reading an Excel file. It uses JExcel API:
    package com.quicklyjava;
    import jxl.*;
    import jxl.read.biff.BiffException;
    import java.io.File;
    import java.io.IOException;
    public class JavaExcelRead {
    * @param args
    public static void main(String[] args) {
    try {
    //Create a workbook object from the file at specified location.
    //Change the path of the file as per the location on your computer.
    Workbook wrk1 = Workbook.getWorkbook(new File("C:/test.xls"));
    //Obtain the reference to the first sheet in the workbook
    Sheet sheet1 = wrk1.getSheet(0);
    //Obtain reference to the Cell using getCell(int col, int row) method of sheet
    Cell colArow1 = sheet1.getCell(0, 0);
    Cell colBrow1 = sheet1.getCell(1, 0);
    Cell colArow2 = sheet1.getCell(0, 1);
    //Read the contents of the Cell using getContents() method, which will return
    //it as a String
    String str_colArow1 = colArow1.getContents();
    String str_colBrow1 = colBrow1.getContents();
    String str_colArow2 = colArow2.getContents();
    //Display the cell contents
    System.out.println("Contents of cell Col A Row 1: \""+str_colArow1 + "\"");
    System.out.println("Contents of cell Col B Row 1: \""+str_colBrow1 + "\"");
    System.out.println("Contents of cell Col A Row 2: \""+str_colArow2 + "\"");
    } catch (BiffException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    You can further process this to convert the data extracted into XML. Hope this helps!

  • Java Code to Convert a file (license) in Excel's CVS Format

    Hi!
    Can anyone suggest me the Code to convert a File in a very specific format that we can read in Excel liek CVS Format of Excel?
    Thanks
    Bob

    What is the format of the License file? Is there a format like .licence format or something like that. Excel recognizes CSV's. So if you can expand the format of the incoming licence file, I may be able to help you.

  • Packages that convert hex to dec

    hi,
    i have a table posicional which has large object on it..the column grarep(graphical representation) and attr_posn contains hexadecimal value of coordinates that is used in automated mapping
    SQL>DESCRIBE POSICIONAL;
    Name          Null     Type
    class_id           NUMBER(10)
    class_memb NUMBER(10)
    codigo               NUMBER(10)
    simbolo               NUMBER(10)     
    xmin               NUMBER(10)
    ymin               NUMBER(10)
    xmax               NUMBER(10)     
    grarep               BLOB
    attr_posn          BLOB
    usuario               VARCHAR2(30)
    fecha               DATE
    texto               VARCHAR2(50)
    --Once i query grarep and attr_posn
    SQL>SELECT grarep from posicional;
    Column or attribute type cannot be displayed by SQL
    --I made a function blobtochar to be able to view the data on grarep and attr_posn
    CREATE OR REPLACE FUNCTION Blobtochar (field_name IN BLOB)
    RETURN VARCHAR2 IS
    OutputStr VARCHAR2(32767);
    -- OutputStr LONG;
    AmtToRead NUMBER:=4000;
    Position NUMBER:=1;
    LENGTH NUMBER;
    BEGIN
    LENGTH := DBMS_LOB.GETLENGTH(field_name);
    LOOP
    OutputStr := OutputStr || DBMS_LOB.SUBSTR(field_name, AmtToRead, Position);
         Position := Position + AmtToRead;
         LENGTH := LENGTH - 4000;
         EXIT WHEN LENGTH < 4000;
    END LOOP;
    RETURN OutputStr;
    END Blobtochar;
    SQL>SELECT blobtochar(grarep) from posicional
    --now i can view the data in grarep..
    --for example
    SQL>SELECT class_memb, blobtochar(grarep) FROM posicional WHERE class_memb=111025648;
    blobtochar(grarep)
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    HERES MY QUESTION,
    1.how can i convert this hexadecimal coordinates so that when i query, a decimal value will appear instead of hex. this hex values are the lines in the map.heres the info about the hex value above. we need to parse or cut the hex into 8..
    00000001
    00000001
    00000006 ==>number of coordinates(ranging from 1-F, this example means 6)
    06D4E833 ==> X1
    074B69EC ==> Y1
    06D4E91F ==> X2
    074CO184 ==> Y2
    06D50C58 ==> X3
    074C031E ==> Y3
    connecting 4 coordinates/2points/ will make 1 line
    connecting 6 coordinates/3points/ will make 2 lines
    connecting 8 coordinates/4points/ will make 3 lines
    connecting 10 coordinates/5points/ will make 4lines
    connecting 12 coordinates/6points/ will make 5lines
    connecting 14 coordinates/7points/ will make 6lines
    and so on..
    In the example above there are 6 coordinates
    point(X1Y1), point(X2Y2), and point(X3Y3). Connecting all 3 points will make 2 lines). computing the total length by phytagorean therorem
    LINE1 length=square root of X2-X1 squared + Y2-Y1 squared
    LINE2 length=square root of X3-X2 squared + Y3-Y2 squared
    total length = LINE1 + LINE2
    how can i implement this so that when i query specific grarep and attr_posn, a computed total length in decimal value will appear instead of hex..thanks

    You might enjoy reading the SQL Reference manual. Chapter 2 deals with datatypes and numeric format models - for 9i the reference you need is http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/sql_elements4a.htm#34512

  • 3DES - Php crypto codes 2 Java codes convertion problem

    I give all php and java codes I convert one by one but I didnt get same result where is my mistake and what shall I do. Thanks for all.
    Php Code
    $key = "db9ca45ee012dcabaff193ca";
    $input = sha1("MehmetKaraman");
    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted_data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    echo sha1(bin2hex($encrypted_data));
    Output : d7eaa53ab43683a1323cfae877a24efb4a918411
    Java Code :
    String message= “MehmetKaraman”;
    byte[] input = MessageDigest.getInstance("SHA1").digest(message.getBytes("utf-8"));
         final Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
         final SecretKey key = new SecretKeySpec("db9ca45ee012dcabaff193ca".getBytes("utf-8"), "DESede");
    cipher.init(Cipher.ENCRYPT_MODE, key );
    if( input.length % 8 != 0){
         byte [] in2 = new byte[input.length+ 8- input.length%8];
         for(int i = 0;i<input.length;i++){
         in2=input[i];
         input = in2;
         final byte[] encrypted_data = cipher.doFinal(input);
         System.out.println(bin2hex(MessageDigest.getInstance("SHA1").digest(bin2hex(encrypted_data).getBytes())));
    Output : 626b61642ec4ba8f7467933832619d492a6fdde1

    Either you need$input = sha1("MehmetKaraman", true);or in your Java you need to hex encode your sha1 digest before encrypting. When I do either of these and emulate your Java bin2hex() method I get a match.
    I don't understand why people seem unable to do simple debugging. If you had read the PHP documentation for the sha1() function and had printed out the results at each stage it would have been obvious.
    P.S. The zero padding implemented by your codeif( input.length % 8 != 0){
    byte [] in2 = new byte[input.length+ 8- input.length%8];
    for(int i = 0;i<input.length;i++){
    in2=input[i];
    input = in2;
    }can be replaced by 1 line using one of the methods in class java.util.Arrays.
    Edited by: sabre150 on Sep 15, 2010 3:10 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Creating XML from java Code

    Hello @ll,
    I need a java code to convert XML file ,which has one node to again a XML file with multiple nodes,depends on the content of source XML File....
    The source structure is something like this:
    <Name>abcd;xyzw;prs</Name>
    and the target structure is something like:
    <FirstNAme>abcd</FirstNAme>
    <MidNAme>xyzw</MidName>
    <LastName>prs</LastName>
    the length of the data is not fixed. and ";" is used as a seperator.
    I have hundred such nodes on the target side.
    How do i acheive this
    Thanks in Advance.
    With Regards,
    BVS

    DEVELOPEMENT-THRILL wrote:
    hi ,
    what i think he can convert the xml to java object by using xstream then he can do his desired work in java and again he can convert it to xml by using xstream again.
    RegardsAn enormous waste of time, though. His "desired" work doesn't need any Java at all, beyond maybe kicking off the transform. Seriously, you've given some poor advice - as we all do from time to time - just accept it rather than try to justify it in retrospect. One of the biggest mistakes you can make as a developer is to use the same tool for everything simply because you already know how to. XSLT and XPath are enormously useful tools to have kicking about, and pretty trivial to learn as well. What could take dozens of lines of Java to achieve could take a single XPath query. Which would you prefer?

  • Looking for Java Image Format converter

    hi,
    I am looking for an open-source site or so, which has Java code on converting different Image types eg. gif/jpeg etc. to PNG. I am building an application which needs to display images. It would be great to have a tool which takes the image and converts it to the PNG format.
    Can anyone help me out?
    cheers :)
    cleoppatra

    hi cleo. there is no tool you can patch into your source. there are two posibilities that i know of.
    1. take a look at the algorith for gif and jepg and chang it to png.
    2. send the link to a server, which you have to program, as a servlet, which will get the html page just as the midp would do, have a normal converter jpg -> png or gif -> png, see if what type of image it is, choose the right converter and convert the pic. format the text the way you want and then send it to the mobile phone. this will make most of the work be much faster since the mobile phone is very slow, and wont be very evectif on converting stuff.
    think about it.
    jeliel

  • Convert Access Module to SQL Function - Hex To Dec conversion

    I need to convert an Access Module to a SQL Function but not sure how to successfully accomplish this.
    The module has several different functions to convert hexadecimal numbers to decimal and vice versa. I am not sure if I needed to break out each module function into a seperate function in SQL or not. Any help would be appreciated.
    Here is the actual module that needs to be converted:
    Public Function MEID_DecToHex(mMEIDDec As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As Double
        Dim mSerialNum As Double
        Dim mMEIDHex As String
        Dim mManHex As String
        Dim mSerialHex As String
        'mMEIDDec = "268435457304109828"
        '*** Check MEID digits, make sure it is 18 digits else return invalid
        If Len(mMEIDDec) = 18 Then
            '*** 18 digit decimal code: 1st 10 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 10)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 8)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        ElseIf Len(mMEIDDec) = 11 Then
            '*** 11 digit decimal code: 1st 3 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 3)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 2)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        Else
            MEID_DecToHex = "Invalid"
        End If
    End Function
    Public Function MEID_HexToDec(mMEIDHex As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As String
        Dim mSerialNum As String
        'Dim mMEIDHex As String
        Dim mManDec As String
        Dim mSerialDec As String
        'mMEIDHex = "a000001937b27a"
        ' Remove any spaces befor or after the string
        mMEIDHex = Trim(mMEIDHex)
        '*** Check MEID digits, make sure it is 14 digits else return invalid
        If Len(mMEIDHex) = 14 Then
            '*** 14 hexadecimal digits: 1st 8 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 8)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Hex to Dec
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 10)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        ElseIf Len(mMEIDHex) = 8 Then
            '*** 8 digit Hex code: 1st 2 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 2)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Dec to Hex
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 3)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        Else
            MEID_HexToDec = "Invalid"
        End If
    End Function

    Try link
    you can create & use CLR function
    or you can simply convert on fly refer below link
    http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal/
    http://blog.sqlauthority.com/2012/07/26/sql-server-answer-how-to-convert-hex-to-decimal-or-int/
    decimal to hex
    http://stackoverflow.com/questions/13643729/decimal-to-hex-conversion-in-sql-server-2008

  • Convert Below Java code equivalent to c# windows store app.

    Hi
    please help me " To convert Below Java code equivalent to c# windows store app."
    private String SecretKey = "enctsbqrm6hxyjfa";
        public byte[] encrypt(String text) throws Exception
            if(text == null || text.length() == 0)
                throw new Exception("Empty string");
            // convert key to bytes
            byte[] keyBytes = SecretKey.getBytes("UTF-8");
            // Use the first 16 bytes (or even less if key is shorter)
            byte[] keyBytes16 = new byte[16];
            System.arraycopy(keyBytes, 0, keyBytes16, 0, Math.min(keyBytes.length, 16));
            // convert plain text to bytes
            byte[] plainBytes = text.getBytes("UTF-8");
            // setup cipher
            SecretKeySpec skeySpec = new SecretKeySpec(keyBytes16, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
            //byte[] iv = new byte[16]; // initialization vector with all 0
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
            // encrypt
            byte[] encrypted = cipher.doFinal(plainBytes);
            return encrypted;
      Thanks            
      Nitin

    Hello Nitin,
    Your current requirement is beyond the scope of our support for this fourm which is used to Discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection.
    If you want to know how to encrypt/decrypt in windows store app, I suggest that you could post a it to:
    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=winappswithcsharp
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Convert SQL statements to JAVA Code ?

    Using SQL queries Can I convert SQL statements to JAVA Code ?
    Edited by: user11238895 on Jun 7, 2009 10:54 PM
    Edited by: user11238895 on Jun 7, 2009 11:12 PM

    Me very new to Oracle.
    can we convert SQL Queries to JAVA Code using simple built in SQL queries ?
    Which SWISS SQL Tool does [Converting SQL Queries to JAVA Code]

Maybe you are looking for

  • IF SD is core module and if we want to Integrate with MM,FI and other mdls

    Hi SD is our core module and  if  i have to test SD module with other module like FI,HR etc how do we do that

  • [SOLVED]Oracle jre / jdk conflicts

    Hi, I just recently installed arch for the first time and is attempting to replace OpenJDK with the version of Oracle. I downloaded the jre and jdk from AUR, but I get conflicts between them. The JDK is needed for development purposes. I extracted th

  • How can i get Mac OS X 10.7.2?

    I have a MacBook Pro and it is only 2 years old. I don't remember what OS X processing system I have but is it really that outdated already? So I was wondering if there was a way to install or download the Mac OS X 10.7.2?  (I am trying to set up iCl

  • How 's route schedule determination in SO

    Hi, Experts, We want active route schedule in SO for our biz requirement. I have do some customizing in system , Route can be determinate auto , but route schedule still not active. below is my setting in SAP 1.Active delivery scheduling & Transport

  • CS5 contrast problem while printing

    I've got at problem with my color settings in Photoshop Cs 5. All pictures look completely normal on screen - this has been tested on different computers and monitors. The contrast and colors are also fine. But, when printing the picture, that means