Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Login to participate.
|
|||||||
Java problem (filling an array with the ascii table)
![]() |
| Thread Tools |
|
#1
|
||||
|
||||
|
Java problem (filling an array with the ascii table)
Hello
![]() I've stumbled onto a problem on my latest assignment at the university, and hopefully someone can help me out... The assignment says to create an array with 256 slots, which shall be filled with lists. The first node of each list shall be a char from the ascii table . Now I know the first 32 entries on the ascii table are non-printing characters, and thus could be skipped, but the assignment calls for an array with 256 slots, so I want to fill them. Now what my problem is: How can I convert an int to a String with the corresponding ascii character? Ie. "101" to "e", "173" to "¡". I know that using the following code will convert from characters to the corresponding ascii number, but I can not fathom how to convert it back Code:
test = Integer.getInteger(readChar);
test = new Integer(readChar);
//can use either of the methods above
value = test.intValue();
)My plan is to use the integer value in the array (due to the first 32 characters) and use .charAt(0) (converted to integer using (some of) the above code) to see where in the array to search for the word). I know by doing that I don't need to convert back to characters, but I'll need characters for a full printout of the array so.... Any help is appreciated! TIA ![]() Last edited by MrGaribaldi; 05-10-2004 at 05:28 PM. |
|
#2
|
||||
|
||||
|
You want to print out a number in human readable form?
The String class contains static functions to convert numbers. You would do sth like: myString=String.valueOf(myByte); System.out.println(myString); I am not responsible for syntax errors. It's not like I write code every day.. Or maybe I understood your question wrong.. |
|
|
|
#3
|
||||
|
||||
|
Try this ...
char c = Character.forDigit (myInt, 10); // base 10 used for radix value |
|
#4
|
||||
|
||||
|
Thanks for your input people
![]() Alas, I could get neither of your suggestions to work. But searching for what a "radix value" is, I came across the answer I was looking for... all I had to do was this Code:
int number = 101; char c = (char) number; System.out.print(c); (Been in a foul mood today, only playing Bf1942) |
|
#5
|
||||
|
||||
|
Oh.
I misunderstood your problem then.. You might as well do System.out.print((char)101); then. |
|
#6
|
||||
|
||||
|
Yeah... that might've worked too...
here's (part of) what the final result became... Code:
firste = newWord.charAt(0);
place = (int) first;
if(wordList[place] == null){
wordList[place] = new Word(newWord, spam, null);
return;
}else {
next = wordList[place];
}
|
|
#7
|
|||
|
|||
|
hi every body!
perhaps this code will be helpfull for you! i found it here:http://www-128.ibm.com/developerwork...j-mer1022.html import java.nio.*; import java.nio.charset.*; import java.util.Arrays; public class Convert { public static void main(String args[]) { System.out.println(Charset.availableCharsets()); Charset asciiCharset = Charset.forName("US-ASCII"); CharsetDecoder decoder = asciiCharset.newDecoder(); byte help[] = {72, 101, 108, 112}; ByteBuffer asciiBytes = ByteBuffer.wrap(help); CharBuffer helpChars = null; try { helpChars = decoder.decode(asciiBytes); } catch (CharacterCodingException e) { System.err.println("Error decoding"); System.exit(-1); } System.out.println(helpChars); } bye :knock: |
|
|
![]() |
| Thread Tools | |
|
| Similar Topics | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Recommendations for RAID 0 Stripe Size | Phantasm66 | Storage & Networking | 17 | 08-16-2006 09:33 PM |
| Erratic problem, sometime no boot-picture | Per Hansson | CPUs, Chipsets and Mobos | 3 | 10-21-2003 06:38 AM |
| Sun suing MS - commentary | lokem | News & Interesting links | 7 | 03-21-2002 06:21 AM |
All times are GMT -4. The time now is 06:43 AM.




