Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double liczbaF(String lancuch) {
- int znakLiczby = 0;
- if(lancuch.charAt(0) == 1) znakLiczby = 1;
- int cecha = 0;
- for(int i = 8, pos = 0; i >= 1; i--, pos++){
- if(lancuch.charAt(i) == '1') cecha += Math.pow(2, pos);
- }
- cecha -= 127;
- double mantysa = 0;
- for(int i = 9, pos = -1; i <= 31; i++, pos--){
- if(lancuch.charAt(i) == '1') mantysa += Math.pow(2, pos);
- }
- mantysa += 1;
- double wartoscLiczby = mantysa * Math.pow(2, cecha);
- if(znakLiczby == 1) wartoscLiczby *= (-1);
- System.out.println("Liczba: " + lancuch + "\nCecha: " + cecha + "\nMantysa: " + mantysa + "\nReturn: " + wartoscLiczby);
- return wartoscLiczby;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement