fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9.  
  10. public static void main(String argv[]){
  11. String nux="ª";
  12. String nux2="Ø";
  13. String nux3="(";
  14. byte []bites = nux.getBytes();
  15. byte []bites2 = nux2.getBytes();
  16. byte []bites3 = nux3.getBytes();
  17. System.out.println(AsciiToBinary(nux));
  18. System.out.println(AsciiToBinary(nux2));
  19. System.out.println(AsciiToBinary(nux3));
  20. System.out.println("number of bytes :"+bites.length);
  21. System.out.println("number of bytes :"+bites2.length);
  22. System.out.println("number of bytes :"+bites3.length);
  23.  
  24.  
  25. }
  26.  
  27. public static String AsciiToBinary(String asciiString){
  28.  
  29. byte[] bytes = asciiString.getBytes();
  30. StringBuilder binary = new StringBuilder();
  31. for (byte b : bytes)
  32. {
  33. int val = b;
  34. for (int i = 0; i < 8; i++)
  35. {
  36. binary.append((val & 128) == 0 ? 0 : 1);
  37. val <<= 1;
  38. }
  39. binary.append(' ');
  40. }
  41. return binary.toString();
  42. }
  43.  
  44. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
11000010 10101010 
11000011 10011000 
00101000 
number of bytes :2
number of bytes :2
number of bytes :1