Advertisement
Guest User

luwer

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1.     public static double liczbaF(String lancuch) {
  2.         int znakLiczby = 0;
  3.         if(lancuch.charAt(0) == 1) znakLiczby = 1;
  4.  
  5.        
  6.         int cecha = 0;
  7.         for(int i = 8, pos = 0; i >= 1; i--, pos++){
  8.             if(lancuch.charAt(i) == '1') cecha += Math.pow(2, pos);
  9.         }
  10.         cecha -= 127;
  11.        
  12.         double mantysa = 0;
  13.         for(int i = 9, pos = -1; i <= 31; i++, pos--){
  14.             if(lancuch.charAt(i) == '1') mantysa += Math.pow(2, pos);
  15.         }
  16.         mantysa += 1;
  17.        
  18.         double wartoscLiczby = mantysa * Math.pow(2, cecha);
  19.         if(znakLiczby == 1) wartoscLiczby *= (-1);
  20.        
  21.         System.out.println("Liczba: " + lancuch + "\nCecha: " + cecha + "\nMantysa: " + mantysa + "\nReturn: " + wartoscLiczby);
  22.        
  23.         return wartoscLiczby;
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement