Int to ASCII

When I try to convert int values to ASCII code, some of the characters are displayed as "?". For example value 144. How can I display those characters correctly?

You are confused. ASCII only defines code points between 0 and 127. Perhaps you had some other charset in mind?

Similar Messages

  • Setting text of a JLabel in an array

    Hey everyone. Im making a spreadsheet type program, but i have hit a brickwall and for the life of me i can't figure out what is wrong. What i'm trying to do, is check if the input in a cell is in the form e.g "=A3". Then i want the program to goto A3, copy what is in that cell and put it in the active cell. I've done the first bit, which is checking the input is in the form of e.g "=A3" using regex, and that works fine, the actual method doesn't seem to work for me, even though i manage to get the position of A3.
    Here is my code:
                   String s = inputdata.getText();
              String regexp = "=[A-Z]{1,2}[1-9]{1}[0-9]*";
              if (s.matches(regexp)){
                   String temp =  s.substring(1,2);                    //extracts the letter from the regex
                   char letter = temp.charAt(0);                         //converts the extracted letter to char indirecting using charAt
                   String temp2 = s.substring(2);                         //extracts the number from the regex
                   int number = (int)temp2.charAt(0);                    //stores the number from the regex in a int variable this is the row number
                   System.out.println(temp);                              
                   System.out.println(temp2);
                   int ascii = (int)letter;                              //converts the char letter to its ASCII code
                   int i = ascii - 64;                                        //gets the number of the column
                   System.out.println(i);
                   String textHolder = cell[number].getText();     //gets the text in [row][column] typed in
                   System.out.println(textHolder);          
                   tempcell.setText(textHolder);                         //sets the text of the active cell to the contents of the cell reference entered.
              }I get an arrayindexoutofbounds error.
    i don't see why its an array index out of bounds. My array cells is size [51][31]. Tempcell is the current active cell determined by another method.
    Any ideas?
    Edited by: kev_x on Apr 30, 2008 6:28 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    When you get an index out of bounds error, it tells you what index it tried to access. Like:
    ArrayIndexOutOfBoundsException: -1That would mean that you tried to access index -1.
    So what does your error tell you?

  • Ignoring spaces and non-alphanumeric characters

    I need some help with this program im working on. It's testing to see whether words are palindromes or not. The trouble is, i need to make the program ignore spaces and puncuation. Does anyone know of a command to do this, or a command where i can list all the common types of puncuation and get the program to ignore them.
    Thanks

    you can use regular expressions (regex) for this. I'm not very experienced with regex (though I admit I should become familiar with it ;)), so for more information check out Sun's regex tutorial and regular-expressions.info.
    if you're not interested in regex (or if you don't have access to a 1.4+ SDK), you can just use ASCII filtering to achieve this (see this ASCII table for basic ASCII values). Basically, you're only going to accept A-Z and 0-9 characters (if I understand your question correctly). This means the only ASCII values you want to accept is 48-57, 65-90, and 97-122. You can use a simple boolean method to check if a character is valid. Something like this should work:
    public boolean valid(char c) {
         int x = (int)c; // ascii value of c
         return ((x >= 48 && x <= 57) || (x >= 65 && x <= 90) || (x >= 97 && x <= 122));
    }Use this method on every character of the String you want to process. So to validate an entire String you can use a method like this:
    public boolean valid(String s) {
         for (int j = 0;j < s.length();j++) {
              if (!valid(s.charAt(j))) {
                   return false;
         return true;
    }Beware though that this is considerably slower than using regular expressions. Also I didn't compile this example so there might be a small mistake you'll have to fix.

  • Req. help on converting int value to a character(ASCII?)

    I have an array, letter[x]...where x is an int from 0 to 26. Each element is storing the freq of a particular letter in a piece of text.
    how do I convert back so that I can store the most freq letter in a string...I presume it's by using the ascii code but I don't know how.
    here's the problem code...
    if (letter[x]>currentMostCommon)
    mostCommonLetter=x; // Don't want value of x, I want ascii for letter "a" ie. x+97
    }

    Yes, it was meant to be 0-25...silly error.
    Thanks for the advice, however your suggestion gives an error:
    C:\MYDOCU~1\SUBJECTS\COMPPR~1\MYPROG~1\ASSIGN2\AnalyseText.java:61: possible loss of precision
    found : int
    required: char
                   char c= 'a' + x;
    any suggestions?
    Paul

  • How can i convert values in my string to ascii characters

    Hi guy.
    I am wrinting a code but i m stuck, I have a string with (Battle of Midway) in it, Now i want to convert each character in this string with the asci character,,,
    String temp = {"Battle of Midway"};
    so the ascii will be:
    B=66 a=97 t=116 l=108 e=101 o=111 f=102 M=77 i=105 d=100 w=119 y=121
    i found all these number for all the charachers, but i donno how to covert this string into ascii characerts... ofcurse i can do it one by one...but is there any class or method i can use for this,,,,, Once i convert all the character (from string) to ascii character THEN i have to convert it back from ascii to character,,
    Is anybody has any idea
    Thanks alot in Advance

    You get get the ascii code for those characters by doing something like:
    int ascii = str.charAt(0); //Get ascii value for the first character.
    Kaj

  • Convert char to ascii

    Hello,
    How can i convert a char to ascii, and ascii to char??
    thanks,
    Riss

    its quite simle really.
    // 199 is the ascii value for 'w';
    char doubleU = 119;
    System.out.println(doubleU);
    //or
    String doubleUString = "119";
    doubleU = (char) Integer.valueOf(doubleUString).intValue();
    System.out.println(doubleU);
    //to get the ascii value of a letter
    System.out.println(doubleU);
    doubleUString = "w";
    doubleU = doubleUString.charAt(0);
    System.out.println(doubleU);
    System.out.println((int) doubleU);

  • Please help me in reading the ascii file in encoded format

    hi ,
    iam trying to read the ascii file and i need to encode the text file, can u suggest me what arre the different methods are availble for me to encode the text file, please suggest me which is the effiecient method tto use?

    This question has been answered before, please search the forums in future.
    You could do something like this, it probably not the most efficient though.
    If you don't need to do it in code then the native2ascii does this conversion see: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html
            public static void convert(String vsFile) throws IOException
              File f = new File(vsFile);
              FileReader fr = new FileReader(f);
              char[] buf;
              int bytesRead = 0;
              int startAt = 0;
              String content = "";
              do
                   buf = new char[512];
                   bytesRead = fr.read(buf, 0, 512);
                   startAt += bytesRead;
                   String tmp = new String(buf);
                   content += tmp;
              while (bytesRead == 512);
              FileOutputStream fout = new FileOutputStream(f);
              OutputStreamWriter out = new OutputStreamWriter(fout, "UTF-8");
              out.write(content.trim());
              out.flush();
              out.close();
         }

  • Characters from VISA not in ascii

    I am using ARM Cortex Microcontroller. I am sending the numbers into lab view through usb port.
    In such case, the strings obtained from VISA Read are not ascii but i can convert them into unsigned int with the help of string to uint premitive.
    The numbers to be sent are continuous and they consist of u8, u16 and also float values.
    So the problem here is the conversion. only those value which are defined as u8 are displayed correctly.
    How do i convert into appropriate values.
    E.g. if the value is integer but greater than 255 i should be able to read and display.
    If the value is float i should be able to display the proper float number.
    I also tried with scan string premitive, also string to number premitive. They can only read ascii and convert, but the characters i am converting are not ascii.
    The characters i am receiving look like boxes and for a value of 0 they are empty space.
    To convert a number into ASCII in my microcontroller could also be possible but the requirement here is with lab view. Microcontroller currently has huge load of programs.
    I would be happy if someone whould help me in this.
    Thanks in advance.
    Solved!
    Go to Solution.

    Sorry for the mistake to write it is string to byte.
    The necessary clippings are as below. The second clipping 'read buffer' is from a series of transformation where, first data is 300, second is 1 and third is 1.23. The output for these as seen in the third picture is 44, 1 and 1. Yes, 300-256 = 44, previously i wrote 45.
    According to you, do you mean that the first two byte should correspond to 300 ? and also similar for the float (not only one byte value but with several values in consecutive elements of the array)?
    I would be happy if similar clips would be avialable.

  • Converting a Text Document to ASCII

    | Test Application
    | Created by Aaron
    | Last Updated 7th March 2008
    import java.io.*;
    import javax.swing.*;
    class Test {
    public static void main(String[] args) throws IOException {
         BufferedReader readSecretMessage = new BufferedReader(new FileReader("SecretMessage.txt"));
         JOptionPane.showMessageDialog(null, readSecretMessage.readLine());
         do {
         int ASCII= 98; // Example
         String yourString= ""+((char)ASCII);
         JOptionPane.showMessageDialog(null, yourString);
         while(readSecretMessage.read() != -1);
    }     Heres my testing code so far... It's wrong i know! But i'm really stuck... I want to convert the txt document "SecretMessage.txt" to ASCII characters and shift the characters 13 places (so for example B will become O, etc)... Any tips and pointers? I know i'm essentially there...Any help appreciated.

    TheMungo wrote:
    Ok... No I don't.
              String foo = "abcde";
              for (int i = 0; i < foo.length(); i++)
              System.out.print((int) foo.charAt(i)+13);
              }How do I get back to characters after?As posted above:
    Than you cast back with (char).But I don't think that will mean anything to you.
    Lets break this down into smaller tasks. The first is to turn a char into a number. We can do this by something called a "cast". so:
    char myChar = 'a';
    int myCharAsAnInteger = (int)myChar;See the () bit, that "casts" the char into an integer.
    The next task is to add an amount to the integer (and handle overflows and stuff, but we shall deal with that later). I'll let you do this part.
    Finally we have to take a integer and make it a char again. Using what is shown above have a go at this.

  • Writing the ASCII value of a character found in a .txt file

    I have a program that reads in a file and outputs certain characters to a new smaller file. The program works fine (thanks to some forum help) but I now need to print the ASCII value of the characters that are written to the file.
    The problem I'm having (besides writing the ascii value of the char) is that the Unix .txt file has some weird properties. When I run the program on a .txt test file that I created with spaces in it, the program ignores the space characters.
    Yet, when I run the program on the Unix file it wites the 'spaces' to the output file. That is why I want to write/print the ASCII value of the "blank "character in the Unix .txt file.
    I already serached the forum and did a Google search for Char to ASCII conversion but I didn't find anything.
    Thanks,
    LS6v
    Here's the code and the clips of the ouput files:
    package source;
    import javax.swing.*;
    import java.io.*;
    public class Scanner4
         public static void main(String[] args)
              getContents();
              System.exit(0);
         public static void getContents()
              char charArray[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                                         'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                                           '0','1','2','3','4','5','6','7','8','9','$','.', '#', '-', '/', '*', '&', '(', ')',' '};
              String Chars = null;
              String lineSep = System.getProperty("line.separator");
              int iterator = 0;
              int i = 0;
              int charNum = 1;
              int lineCount = 1;          
             // StringBuffer contents = new StringBuffer();
             //declared here only to make visible to finally clause
             BufferedReader input = null;
             BufferedWriter out = null;
             try {
                         //use buffering
                         //this implementation reads one line at a time
                         input = new BufferedReader( new FileReader( "C:\\testFile\\test1.txt" ));
                         out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Write\\test.txt" ));
                         String line = null;
                    out.write( "Character\tLine Number\tCharacter Number" + lineSep ); 
                              while (( line = input.readLine()) != null)
                               //contents.append(System.getProperty("line.separator"));
                               i = 0;
                               charNum = 1;
                               iterator = 0;
                              while( i < line.length() )
                                             for( int count = 0; count < charArray.length; count++)
                                                  if( (charArray[count] != line.charAt(iterator)) && (count+1 == charArray.length) )
                                                       out.write( "[" + line.charAt(iterator) + "]\t\t" + "[" + lineCount + "]\t\t" + "[" + charNum + "]" + lineSep);
                                                  if( charArray[count] == line.charAt(iterator) )
                                                       break;
                                        charNum +=1;
                                        iterator +=1;
                                        i++;                               
                                 lineCount +=1;
             catch (FileNotFoundException ex) {ex.printStackTrace();     System.out.println("File not found.");}          
                 catch (IOException ex){ex.printStackTrace();               System.out.println("IO Error.");}
             finally
                           try{
                                 if (input!= null){
                               //flush and close both "input" and its underlying FileReader
                                 input.close();
                                 out.close();
               catch (IOException ex){ex.printStackTrace();  System.out.println("IO Error #2.");}
    My created .txt file:
    1. a!asdsad
    2. @
    3. #
    4. $
    5. %sdfsdf
    6. ^
    7. &
    8. *
    9. (
    10. )
    11. _
    12. +sdfsdfsdf
    13. -
    14. =
    15. ~
    16. `
    17. dfgdfg;
    18. :
    19. '
    20. "fghfghf
    21. ,
    22. dfgdfg<
    23. .
    24. >fghfghfg
    25. /
    26. gggggggggggggggggggggggg?
    27. a
    Output for my .txt file:
    Character     Line Number     Character Number
    [!]          [1]          [5]
    [@]          [2]          [4]
    [%]          [5]          [4]
    [^]          [6]          [4]
    [_]          [11]          [5]
    [+]          [12]          [5]
    [=]          [14]          [5]
    [~]          [15]          [5]
    [`]          [16]          [5]
    [;]          [17]          [11]
    [:]          [18]          [5]
    [']          [19]          [5]
    ["]          [20]          [5]
    [,]          [21]          [5]
    [<]          [22]          [11]
    [>]          [24]          [5]
    [?]          [26]          [29]************************************************************************
    Output generated after reading the .txt file from the unix box:
    Character     Line Number     Character Number
    [ ]          [1]          [17]
    [ ]          [1]          [18]
    [ ]          [1]          [19]
    [ ]          [1]          [6530]
    [ ]          [2]          [2041]
    [']          [29]          [1834]
    [']          [29]          [2023]
    [']          [30]          [1834]
    [']          [30]          [2023]
    [']          [30]          [2066]
    [']          [47]          [2066]
    [']          [67]          [2067]
    [']          [77]          [2066]
    [+]          [80]          [28]

    Thanks I didn't even think to try and cast it to an int...
    The tool I'm using to create my .txt in windows is Notepad.
    I wrote a program to simply copy the original (3GB) Unix file and terminated it early so I could see what was there. What I found was some text and symbols and a lot of space between brief bursts of text. I can't really copy and paste an example because the amount of space is too large, it's basically a 3GB unformatted .txt file...
    Unix file was created on: unknown
    It sounds like the .txt file that I copied from the Unix box was formatted differently. But I thought that the formatting had more to do with end of line issues, not blank space between characters. Because a blank space should be seen by my program and ignored...
    Here's the ASCII value of the "blank" spaces:
    Character     Line Number     Character Number
    [ ]          [1]          [17]     Ascii Value: [0]
    [ ]          [1]          [18]     Ascii Value: [0]
    [']          [868]          [2066]     Ascii Value: [39]
    [,]          [877]          [186]     Ascii Value: [44]
    [,]          [877]          [276]     Ascii Value: [44]
    Also, the Ascii value printed for the blank spaces looks like the number zero here but it looks like it has strange points on the bottom of it in my output file. It looks like the extended ASCII character 234 &#937;

  • How can I get the ASCII code instead of Unicode?

    If I use getNumericValue to return the Unicode of a character, I found out "a" = "A". Is there any way I can find out the different code for capital letter and small letter? I'm thinking about ASCII code, any suggestion for which method to return the ASCII code?

    That is not what getNumericValue does. (Try getNumericValue('*'), for example, and you will see it returns -1.) If you want to find the Unicode value of a character, simply cast the character to an int:char letter = 'A';
    int unicodeValue = (int)letter;If the character you chose was in the ASCII character set, you will automatically have its ASCII code, because ASCII is simply the first 128 characters in the Unicode character set.

  • How to handle ASCII file in file download

    Hi:
    I have an applet that will download mutiple files to client's PC at the background. It handle binary files (e.g. word, excel) OK.
    However, for ASCII file, it lost the line feeds, etc. so my multiple-lines file become 1 line (seems to be transfer via binary mode). Anyway to fix this ?
    The relevant code segment looks like this:
    public class Filedownload extends JApplet
    public Filedownload()
    String FileName1="template2.doc";
    String webFile1 =
    "http://hkzux05/~doracle/dev/"+FileName1;
    String outfile1 =
    "c://dev//mail-merge//" +FileName1;  
    String FileName2="data1.csv";
    String webFile2 =
    "http://hkzux05/~doracle/dev/"+FileName2;
    String outfile2 =
    "c://dev//mail-merge//" +FileName2;   
    try {
    System.out.print("Start downloading file "+FileName1+"\n");
    URL url = new URL(webFile1);
    InputStream in = url.openStream();
    byte[] buf = new byte[1024];
    int len;
    OutputStream out = new FileOutputStream(outfile1);
    while ((len = in.read(buf)) != -1) {
    //write byte to file
    out.write(buf, 0, len);
    //close the stream
    in.close();
    System.out.print("End downloading file "+FileName1+"\n");
    System.out.print("Start downloading file "+FileName2+"\n");
    url = new URL(webFile2);
    in = url.openStream();
    OutputStream out2 = new FileOutputStream(outfile2);
    while ((len = in.read(buf)) != -1) {
    //write byte to file
    out2.write(buf, 0, len);
    in.close();
    System.out.print("End downloading file "+FileName2+"\n");
    System.out.print("... Done ...\n");
    catch (MalformedURLException e){
    //TODO
    catch (IOException e){
    //TODO:FileNotFoundException caught here
    finally{
    //TODO
    Thks

    Can anyone help ?
    Thks

  • Problem while unzipping the non-ascii characters

    we are not able to retain the greek characters after zipping the files(that contain greek characters). the following code shows u a clear sketch about how we are zipping the files on solaris platform.
    ZipOutputStream out = null;
         try
              FileOutputStream f = new FileOutputStream(zipFileName);
              out = new ZipOutputStream(new BufferedOutputStream(f));
              for(int i = 0; i < fileNameLists.getNumElements(); i++)
                   BufferedReader in =     new BufferedReader(     new FileReader(fileNameLists.getNameAt(i)) );
                   out.putNextEntry(new ZipEntry(getFileName(fileNameLists.getNameAt(i))));
                   int c;
                   while((c = in.read()) != -1)
                        out.write(c);
                        in.close();
              out.close();
    if we are directly open the file which is stored in specified location its displaying greek characters(non-ascii) correctly but our application need to zip those files and save on windows platform.
    so once we zip the files and download onto windows platform its and extract the files its shows some garbage characters(may be using defaulr character encoding of windows cp1252) instead of greek charcaters.
    we tried in many ways using the setEncoding() method in ZipOutPutStream even then no use.
    is it because that zip utility while reading takes default character encoding of the platform?
    wud be thankful if anyone cud provive solution for this

    String encodingFormat = "UTF-8";
    BufferedReader in = new BufferedReader( new FileReader(fileNameLists.getNameAt(i)), encodingFormat );try the above code n let me know if its helpful

  • Non ASCII String to Hex

    Hi,
    I am writing an algorithm that first encrypts a String, and then converts that String to Hex String. I can successfully parse Hex Strings into Ascii Strings and vice versa, but when I encrypt I cannot do this anymore. Is there a way to convert a non-ascii character to Hexadecimal and vice versa?
    Thanks in advance

    Maybe so....
    The encrypted value when printed does not format on my screen, and appears as boxes and such.
    The values that I am passing in are a very simple encryption....XOR against a key. Here is that algorithm.
    public byte[] encrypt(byte[] value) {
              byte[] encrypted = new byte[value.length];
              byte[] adjustedKey = getKey();
              while (adjustedKey.length < encrypted.length) {
                   String temp = new String(adjustedKey) + new String(key);
                   adjustedKey = temp.getBytes();
              for (int i = 0; i < value.length; i++) {
                   encrypted[i] = (byte)(adjustedKey[i] ^ value);
              return encrypted;          
    Since this is an XOR, I can use the same method to decrypt as well. This is what produces my non-Ascii characters.
    Is there a way for me to get the byte value of a 1 digit hex value then? this may help some.

  • Convert non-ASCII character to decimal value

    Hi all,
    I have the following problem:
    When reading a String containing the full spectrum of UTF-8 characters from a BufferedReader:
    How can I get the decimal value of the String's characters outside the ASCII range?
    When I try to do a MyBufferedReader.read(), I get the int value 65533 for these characters, instead of their real value in the UTF-8 set.
    Can anyone help?
    Thanks!
    Dre

    That's the character you get when you try to decode a character with no valid decoding. Of course there aren't any such characters for UTF-8. Therefore whatever you did, don't do that. More specifically: you've already got a String, don't do anything which involves converting it to bytes. That's completely unnecessary.
    Or perhaps the problem is the way you create the String in the first place. Who knows?

Maybe you are looking for

  • Photoshop CC won't open Adobe Camera Raw because of disk error

    When I try to open a raw file from a Canon 60D, Photoshop CC does not open the file and displays an error:  "Could not complete your request because of a disk error". It does not matter whether you drag the file onto the Photoshop icon to open it, or

  • This message could not be delivered?

    I bought a .Mac account and it set up everyone on my computer automatically. When I open Mail and try to send mail I get an error message saying: This message could not be delivered and will remain in your Outbox until it can be delivered. The connec

  • UCXX agent are reserved state

    IN UCXX 7.0 , every day two to three times ucxx agent are getting reserved starte, then we are restaring the CXX services. As per cisco document, I enable the interruptible option under the palyprompt, but no any success.

  • 32 bit and 64 bit versions of Smartview

    Does anyone know how to add two different versions of the smartview downloadable file to the Tools->Install (Dropdownd Menu) in HFM's workspace. Basically, I want to have available the 32 and 64 bit versions of Smartview for downloading directly from

  • Division between fert and halb

    In my orgn two diff type of products where being manufactured therefore at finished goods (FERT) material code level two divisions where used, but for all the components assigned to the main material in bom I was using only one division For exampe FE