Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Naloga11 {
- int pretvoriZnak(String znak) {
- int result = 0;
- int power_of_two = 1;
- for(int i = znak.length() - 1; i >= 0; i--) {
- if(znak.charAt(i) == '1') {
- result += power_of_two;
- }
- power_of_two *= 2;
- }
- return result;
- }
- String pretvoriZnake(String znaki) {
- StringBuffer sb = new StringBuffer();
- for(int i = 0; i < znaki.length(); i += 8) {
- String tmp_str = "";
- for(int j = i; j < i + 8; j++) {
- tmp_str += znaki.charAt(j);
- }
- int decimalen_broj = pretvoriZnak(tmp_str);
- sb.append((char) decimalen_broj);
- }
- return sb.toString();
- }
- public static void main(String[] args) {
- Naloga11 n11 = new Naloga11();
- System.out.println(n11.pretvoriZnake(args[0]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement