Advertisement
Josif_tepe

Untitled

Jun 15th, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. public class Naloga11 {
  2.     int pretvoriZnak(String znak) {
  3.         int result = 0;
  4.         int power_of_two = 1;
  5.         for(int i = znak.length() - 1; i >= 0; i--) {
  6.             if(znak.charAt(i) == '1') {
  7.                 result += power_of_two;
  8.             }
  9.             power_of_two *= 2;
  10.         }
  11.  
  12.         return result;
  13.     }
  14.  
  15.     String pretvoriZnake(String znaki) {
  16.         StringBuffer sb = new StringBuffer();
  17.         for(int i = 0; i < znaki.length(); i += 8) {
  18.             String tmp_str = "";
  19.             for(int j = i; j < i + 8; j++) {
  20.                 tmp_str += znaki.charAt(j);
  21.             }
  22.             int decimalen_broj  = pretvoriZnak(tmp_str);
  23.             sb.append((char) decimalen_broj);
  24.         }
  25.         return sb.toString();
  26.     }
  27.  
  28.     public static void main(String[] args) {
  29.         Naloga11 n11 = new Naloga11();
  30.         System.out.println(n11.pretvoriZnake(args[0]));
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement