Convertion to ASCII code

Hi everybody,
I have string:s, I convert it to an integer in base 16:
int a = 0;
a = Integer.parseInt(s, 16);
How can I convert the integer: a to it's equvalence ASCII code?
Any help is greatly appreciated.

I think we'lll try that again;-
char c = (char)a;Without other info, and based solely on 'ascii' the following is probably better...
      if (a > 127)
          throw new Exception("Can not map value(" + a + ") to ascii");
      char c = (char)a;

Similar Messages

  • Convert HTML ASCII codes with JSTL and Apache Taglibs?

    I am building a web application using JSTL and some of the Apache Taglibs, so these are the taglibs I have at my disposal currently. What I am looking for is the ability to handle the &#039; that appears in submitted search strings which contain the ' character. SQL seems to be able to handle other special characters (such as &, [, ", etc) but I can't get it to get along with the &#039;.  I have tried using a <string:replace replace="&#039;" with="\&#039;"> to escape the &#039;, but this doesn't seem to work either.  Any suggestions?  Let me know if you need more information to be able to fully understand the situation.
    --Ioeth                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    By the way, the search string that a user enters is getting Tokenized using " " as the token and then fed directly into multiple SQL LIKE comparisons based on how many tokens were found.

  • How to convert ascii codes into Strings

    Is it possible to convert integers (ascii codes) into Strings. It cannot be done by casting like:
    int temp = (String)(111)
    Please help me out. I think there is a method for this.

    Something as simple as String.valueOf((char) 111) comes to mind...

  • Ascii Codes

    Is there a function that can convert an ascii code to the proper character?
    ie: in excel, one can use code() and char() to go back and forth.
    Found some ref to \u0041 = A, but not sure if this is the right method?
    Any assistance greatly appreciated.

    Hi,
    CODE("A") could be written in JavaScript as "A".charCodeAt(0), where the argument to charCodeAt is the position in the string so "AB".charCodeAt(1) would give you the code of B
    and
    CHAR(65) could be written in JavaScript as String.fromCharCode(65).  The method fromCharCode can take a list so String.fromCharCode(65,66,67) will return "ABC".
    Bruce

  • Convert char to ascii code and vice versa

    HI
    Is there any function module to convert char to ascii code and vice versa.
    Thanks in advance

    Hi,
    be careful if you have unicode running in your system. URL_ASCII_CODE_GET is platform-dependent so it will return the internal HERX representation of the character in your system - which is hopefully and in most cases ASCII.
    Under unicode, we use double-byte characters here. I tried this function and the result CHAR_CODE is '00' regardless what character I specify for TRANS_CHAR. But the coding is so simple I corrected resultig in this sample code:
    [P]
    convert p_form to ASCII (internal) representation
      DATA:
        l_ofs TYPE syfdpos,
        l_len TYPE sy-linsz,
        l_ascii TYPE i.
      FIELD-SYMBOLS:
        <x> TYPE x.
      l_len = STRLEN( p_ascii ).
      DO l_len TIMES.
        l_ofs = sy-index - 1.
        ASSIGN p_ascii+l_ofs(1) TO <x> CASTING.
        l_ascii = <x>.
        WRITE: l_ascii.
      ENDDO.
    [/P]
    Here, for each character of string p_ascii, the internal (ASCII) representation is determined and written to the output list.
    Regards,
    Clemens

  • Need help with converting characters to ASCII code

    Hey. Im trying to write a program to make Caesar Ciphers by random numbers. This cipher must also wrap from front to end of ASCII code, so that if, for example, the character being ciphered is Z and its being modified by +3, the result ciphered character is not "]", but "c".
    Im planning on reading the text that the user inputs (using ConsoleIO) into a string and then seperating each character into a character[]. Then, i would like to find the ASCII code of each character and print out the ASCII code character of the old ASCII code + the modifier.
    So far, this is what i have (sorry for the length, i like to space things out so that its easier on the eyes and more organized... X-( ... ):
    public class EvanFinalB {
         static ConsoleIO kbd = new ConsoleIO();
         static String enteredPhrase;
         static int phraseLength;
         public static void main(String[] args)
              System.out.println("Enter a phrase and this program will cipher it into a secret message.");
              System.out.println("/nEnter your phrase here:");
              //read phrase
              enteredPhrase = kbd.toString();
              //find length of entered text
              phraseLength = enteredPhrase.length();
              //declare arrays for the individual characters of the entered text and the ciphered characters
              char[] enteredChar = new char[phraseLength + 1];
              char[] cipheredChar = new char[phraseLength + 1];
              //loop converting of entered text into seperate characters
              for(int x = 1; x <= phraseLength; x++)
                   enteredChar[x] = enteredPhrase.charAt(x);
                   cipheredChar[x] = cipher(enteredChar[x]);//call cipher() method to find new ciphered character
         //wrap from front to end of ASCII code
         static char cipher(char enteredChar)
              //choose random number to cipher message by
              int modifier = (int)(Math.random() * 26) + 1;
              if(enteredChar + modifier > 90)//90 is the ASCII code for "Z" which is the last capital letter
                   cipheredChar = (97 + (modifier - (90 - enteredChar)));//97 is the ASCII code for "a" which is the first lower case letter
              return cipheredChar[1];
    }The program is obviously in its early stages but (i started creating it today actually), if there is a simple method or anything that i can use to find the ASCII value of a character in order to use enteredChar so that 'enteredChar' is equal to the ASCII code of the new ciphered character, please help me out...Thanks
    P.S. If there's an easier way to go about creating a program for Caesar Ciphers, let me know.

    The following code is from my Java textbook Big Java by Cay Horstmann. It is not my code and it's just to guide you in your own cipher.
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
       This class encrypts files using the Caesar cipher.
       For decryption, use an encryptor whose key is the
       negative of the encryption key.
    public class CaesarCipher
          Constructs a cipher object with a given key.
          @param aKey the encryption key
       public CaesarCipher(int aKey)
          key = aKey;
          Encrypts the contents of a stream.
          @param in the input stream
          @param out the output stream
       public void encryptStream(InputStream in, OutputStream out)
             throws IOException
          boolean done = false;
          while (!done)
             int next = in.read();
             if (next == -1) done = true;
             else
                byte b = (byte) next;
                byte c = encrypt(b);
                out.write(c);
          Encrypts a byte.
          @param b the byte to encrypt
          @return the encrypted byte
       public byte encrypt(byte b)
          return (byte) (b + key);
       private int key;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Scanner;
       This program encrypts a file, using the Caesar cipher.
    public class CaesarEncryptor
       public static void main(String[] args)
          Scanner in = new Scanner(System.in);
          try
             System.out.print("Input file: ");
             String inFile = in.next();
             System.out.print("Output file: ");
             String outFile = in.next();
             System.out.print("Encryption key: ");
             int key = in.nextInt();
             InputStream inStream = new FileInputStream(inFile);
             OutputStream outStream = new FileOutputStream(outFile);
             CaesarCipher cipher = new CaesarCipher(key);
             cipher.encryptStream(inStream, outStream);
             inStream.close();
             outStream.close();
          catch (IOException exception)
             System.out.println("Error processing file: " + exception);
    }

  • Convert from char to ASCII code

    anyone can advice me on this program why the conversion cannot be done? Thank in advance.
    String charInput = JOptionPane.showInputDialog (null, "Enter a character", "Finding ASCII code", JOptionPane.QUESTION_MESSAGE) ;
    answer = Integer.parseInt (charInput) ;

    Try this code out:
    import javax.swing.JOptionPane;
    public class Crap {
        public static void main (String[] args) {
            String charInput =
                    JOptionPane.showInputDialog (null,
                    "Enter a character", "Finding ASCII code",
                    JOptionPane.QUESTION_MESSAGE) ;
            JOptionPane.showMessageDialog (null, charInput, "Collected Data",
                    JOptionPane.INFORMATION_MESSAGE );
    //        answer = Integer.parseInt (charInput) ; //<-- What datatype?
            String answer = "You never declare the data type for you answer.\n" +
                    "JOptionPane returns a string of what the user enters.\n" +
                    "The first?  The last? Some other position?\n" +
                    "A String != a character.\n" +
                    "Which character of the string do you want to convert?\n" +
                    "You need to do a lot more work on this problem.";
            JOptionPane.showMessageDialog (null, answer,
                    "The Java Compiler hates your code because...",
                    JOptionPane.OK_OPTION, null);
    }http://leepoint.net/notes-java/GUI/containers/20dialogs/10joptionpane.html
    Cheers !
    JJ

  • How can I convert characters into ascii code numbers ??

    Read the characters or String from keyboard input then I want the sum of the ascii code of the String or the characters. Please help ....
    Han

    Read the characters or String from keyboard input
    put then I want the sum of the ascii code of the
    String or the characters. Please help ....
    HanThe keyboard input part is a little more coding envolved. Here is a sample of what can be done if
    you know what to implement. It needs three classes
    from the java.io package. Well, here is the complete
    source code for the 'keyboard input' and a driver
    class to test it.
    //package consoleclass;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    class Driver
         public static void main ( String[] args)
              System.out.println("Enter a number");
              int number = MyInput.readInt();
              System.out.println("number entered "+ number);
              System.out.println("Enter another number");
              number = MyInput.readInt();
              System.out.println("number entered "+ number);
    class MyInput
      /**Read a string from the keyboard*/
      public static String readString()
         BufferedReader br
           = new BufferedReader(new InputStreamReader(System.in), 1);
         // Declare and initialize the string
         String string = " ";
         // Get the string from the keyboard
         try
           string = br.readLine();
         catch (IOException ex)
           System.out.println(ex);
         // Return the string obtained from the keyboard
         return string;
      /**Read an int value from the keyboard*/
      public static int readInt()
         return Integer.parseInt(readString());
      /**Read a double value from the keyboard*/
      public static double readDouble()
         return Double.parseDouble(readString());
    }

  • Apple mail converting attachments into ascii code?!

    Hi,
    I am working on a Retina MBP. For some unexplicable reason sometimes when I move an email between folders in Mail the email seems to become corrupted and turns in to ASCII code (I think). There seems to be no rhyme or reason as to why it sometimes happens and most of the time doesn't. I'll get an email and read it in my inbox then transfer it to a folder and go back to read it and it looks like this:
    --Apple-Mail=_A9B8159A-26EF-4733-9B9D-9A3112F5F60B
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/plain;
         charset=us-ascii
    Hey Tom,
    How are you.=20
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut =
    labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco =
    laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in =
    voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat =
    Thanks,
    Ele
    --Apple-Mail=_A9B8159A-26EF-4733-9B9D-9A3112F5F60B
    Content-Type: multipart/mixed;
         boundary="Apple-Mail=_AF8260B5-4C4F-4338-A6BD-56269F2A5E41"
    --Apple-Mail=_AF8260B5-4C4F-4338-A6BD-56269F2A5E41
    Content-Transfer-Encoding: 7bit
    Content-Type: text/html;
         charset=us-ascii
    <html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hey Tom,</div><div><br></div><div>Bit of advice please. </div><div><br></div><div>Annie wants to play a track called The Anger Games by K9. It contains a sample of Tom Jones in the comedy film Tropic Thunder containing the lyrics:  "Take a big step back and literally **** your own face?" x 6  + *gun sounds* x 2 + "I will **** you up" x 2 + "I'm gonna massacre you." 2</div><div><br></div><div>Track attached</div></body></html>
    --Apple-Mail=_AF8260B5-4C4F-4338-A6BD-56269F2A5E41
    Content-Disposition: attachment;
         filename="01 The Anger Games (Original Mix).mp3"
    Content-Type: audio/mpeg;
         x-unix-mode=0644;
         name="01 The Anger Games (Original Mix).mp3"
    Content-Transfer-Encoding: base64
    SUQzBAAAAAZQMkFQSUMAAmkhAAAAaW1hZ2UvanBlZwADAP/Y/+AAEEpGSUYAAQEAAAEAAQAA/9sA
    QwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8n
    OT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy
    MjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgB9AH0AwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAA
    AAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQy
    gZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVm
    Z2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS
    09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYH
    And then that code goes on for PAGES & PAGES!
    Any suggestions of what's going on welcome. I'm using an IMAP account in Mail FYI.

    Quit Mail. Force quit if necessary.
    Back up all data. That means you know you can restore the Mail database, no matter what happens.
    Triple-click the line below on this page to select it:
    ~/Library/Mail/V2/MailData/Envelope Index
    Copy the selected text to the Clipboard (command-C). In the Finder, select
    Go ▹ Go to Folder
    from the menu bar. Paste into the box that opens (command-V), then press return.
    A Finder window will open with a file selected. Move the selected file to the Desktop, leaving the window open. Other files in the folder may have names that begin with "Envelope Index". Move those files, if any, to the Trash.
    Log out and log back in. Relaunch Mail. It should prompt you to re-import your messages. You may get a warning that the index is corrupt and that Mail has to quit. Click OK.
    Test. If Mail now works as expected, you can delete the file you moved to the Desktop. Otherwise, post your results.

  • ASCII Code in ABAP

    Hi Experts,
    We need to enter a unique ASCII character called 'US' or Unit Separator in a text file being generated through a program.
    The ASCII code for US is 31. However when we try and do it programmatically the character '#' is getting populated.
    The code is as follows:
    DATA : lv_sep type c.
    field-symbols : <xfs> type x.
    assign lv_sep to <xfs> casting.
    <xfs> = 0031.
    write lv_sep.
    Kindly help us out.
    Thanks and Regards,
    Ravi Bhatnagar

    Hi,
    This character is special one, so you can't print it out. In SAP all special charcter which can't be printed are replaced with placeholder #.  They are intended to do theri special purpose in flat file, once you open it.
    Do the following:
    - use fm HR_KR_XSTRING_TO_STRING to convert xstring with value  '1F' (30 decimal value) to string
    - write this string to certain place in internal string table (where you want later use it in the file)
    - download this table as to file
    - special character will do its purpose in text file
    This is the same functionality as you would be placing Line Feed (0x0A - 10 dec). It would be shown as # but once you open downlaoded file you don't see hash # anymore, but you see that new line in that place.
    Hope this is clear
    Regards
    Marcin

  • How do I convert the ASCII output of a Maxtek TM-350 QCM Deposition monitor to a normal string I can read?

    Hi!
    I'm working wiht a Maxtek TM-350 QCM Thickness Monitor, and I am having some trouble deciphering the output from the monitor.  I am using an RS232 interface to communicate with the monitor.  I wrote a little VI to try to just query for the version number of the software that is being used.  The instruction manual said to send the message Chr$(255)+Chr$(254)+Chr$(1)+Chr$(1)+Chr$(0)+Chr$(254).  So, I built an array of those numbers, converted it to a string and sent it out via the Visa Write command.
    From the instruction  manual, I thought I was supposed to get back Maxtek TM-350 Software Version X.XX.  When trying to read what was sent back I tried a couple of things.  First, I just read the string, which looked like a bunch of special characters (squares, y's with dots over them, etc.), which I think is ASCII code.  So, I tried to convert that into a normal string I could read using a scan value command.  That didn't work, so I tried to convert it to a hexadecimal string, which didn't help either.
    I attached my VI and a copy of the instructions manual for the TM-350 below.  Does anyone have some ideas on how I can fix this problem?
    Thanks!
    Piet
    Attachments:
    tm-350400_manual_en_Rev12_10-2005.pdf ‏748 KB
    Maxtek_TM-350_Test.vi ‏32 KB

    It is hard to tell without seeing what you transmitted and what was returned. Try downloading portmon to watch the serial data.
    http://www.microsoft.com/technet/sysinternals/utilities/portmon.mspx
    The attached might get you started.
    Attachments:
    read data from serial port.vi ‏43 KB

  • Unable to print ASCII codes

    Hello,
    I am facing a problem in printing ASCII code between 128 and 159. these codes are displayed as '?'. All the other codes are printed correctly. Please let me know the reason behind this.
    Given below is the code for the same
    class Codes
         public static void main(String args[])
              short i = 165;
              for (i=0; i<=256;i+=5)
                   System.out.println(i+" "+(byte)i+" "+(i+1)+" "+(byte)(i+1)+" "+(i+2)+" "+(byte)(i+2)+" "+(i+3)+" "+(byte)(i+3)+" "+(i+4)+" "+(byte)(i+4));
    Waiting for a quick reply
    rgds,
    Sameer

    1. What are the chars you are talking about? As already mentioned, they are control chars in unicode. What character encoding would you like to use, or in other words, what characters would you like to have for those bytes?
    2. The character encoding of the dos console (Cp850 on the windozes I've used) is different from the system's default encoding (Cp1252, IIRC). This will cause problems if you want to print out text having non-ascii characters. For example System.out.println("&Aring;&Auml;&Ouml;") should print out the last three letters of the finnish alphabet but it prints something else instead. But if you write the text to a file it comes out as it should.
    Another character encoding can be used by wrapping an OutputStreamWriter around System.out:
    OutputStreamWriter osw = new OutputStreamWriter(System.out, "Cp850");
    PrintWriter out = new PrintWriter(osw, true);
    out.println("&Aring;&Auml;&Ouml;");
    Similarly, the input read through the standard inputstream in dos (the keyboard input or redirection using "<") is in another encoding and needs to be converted.

  • How to convert signed ascii hex to float value

    Hi,
    I have a requirement to convert IEEE ascii hex to float value.
    Following code is working for +ve float value but it didn't work for -ve.
    public static float hexToFloat(String str){
              float floatVal= 0.0f;
              int decimalValue =Integer.parseInt(str,16);
              floatVal=Float.intBitsToFloat(decimalValue );
              return floatVal;
    for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
    For the above string I am getting number format exception.
    pls help me.

    The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
    The solution is to use Long.parseLong() instead.
    public static float hexToFloat(String str){
    float floatVal= 0.0f;
    int decimalValue =(int)Long.parseLong(str,16);
    floatVal=Float.intBitsToFloat(decimalValue );
    return floatVal;
    }

  • Extended Ascii Code in Swing

    Hi master,
    I have found some viewing extended ascii code in Swing. The palteform I used is Windows Me.
    It is not viewing properly for some of chars with ascii code more than 127 to 255.
    Any idea would be appreciate.
    Thanks in advance!

    Hi,
    This character is special one, so you can't print it out. In SAP all special charcter which can't be printed are replaced with placeholder #.  They are intended to do theri special purpose in flat file, once you open it.
    Do the following:
    - use fm HR_KR_XSTRING_TO_STRING to convert xstring with value  '1F' (30 decimal value) to string
    - write this string to certain place in internal string table (where you want later use it in the file)
    - download this table as to file
    - special character will do its purpose in text file
    This is the same functionality as you would be placing Line Feed (0x0A - 10 dec). It would be shown as # but once you open downlaoded file you don't see hash # anymore, but you see that new line in that place.
    Hope this is clear
    Regards
    Marcin

  • 'Open Dataset' command - add ASCII code in a unicode system

    Hi,
    I use following comand in order to save a file on an application server. 
    open dataset <path> for output in text mode encoding default.
    Is it possible to convert file to ASCII code instead of the system setting unicode and to ignore conversion errors? If yes, please tell me how.
    Thanks!

    problem exporting text in hebrew
    Similar kind of problem has been solved here.. check that link first
    Use the class CL_ABAP_CONV_OUT_CE and use it to convert file from unicode to ascii.

Maybe you are looking for