Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class Test7{
  2.  
  3. //Aufgabe 1c)
  4. public static String textToBinary(String s) {
  5. for (int i=0; i< s.length(); i++) {
  6. char c = s.charAt(i);
  7. if (c == "\u00C4")
  8. return "11000011" + "10000100";
  9. else
  10. String result = charToBinary(c);
  11. System.out.println(result);
  12. }
  13. return "";
  14. }
  15.  
  16. //Aufgabe 1b)
  17. public static String charToBinary(char c) {
  18. int e = Integer.valueOf(c);
  19. String s = "";
  20. for (int i=0; i<8; i++)
  21. {
  22. s = ( ( e % 2 ) == 0 ? "0" : "1") + s;
  23. e = e / 2;
  24. }
  25. return s;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement