hey there,
I have the following code:
import java.io.*;
public class Karakters{
public static void main(String[] args) throws IOException{
FileWriter in = new FileWriter("karakters.txt");
PrintWriter outfile = new PrintWriter(in);
char x = 'A';
for(int i = 0; i < 300; i++){
System.out.println((i + 1) + " " + (char)(x + i));
outfile.println((char)(x + i));
}
outfile.close();
}
}
This class creates a txt file named karakters.txt, and puts 300 consecutive characters, starting at 'A', in the file, one character each line.
The following class is supposed to generate binary representations of each character using Java's Integer.toBinaryString(character) method. however, this is not working properly. for characters whose ascii values range between 127 and 160 (inclusive), the same value is returned, and it equals 111111 (decimal 63).
import java.io.*;
public class Aski{
public static void main(String[] args) throws IOException{
FileReader x = new FileReader("karakters.txt");
BufferedReader outfile = new BufferedReader(x);
int i = 0;
while(outfile.ready()){
i++;
String s = outfile.readLine();
System.out.println(i + " " + s.charAt(0) + " " + (Integer.toBinaryString(s.charAt(0))));
}
}
}
there are other ranges, like 256 - 365 for which the same occurs. I expect that a character generated as follows:
char x = (char)(270);
would return a binary equivalent of 270 after passed to Integer.toBinaryString() method.
please help! thank you.