Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. import struct
  2.  
  3. getBin = lambda x: x > 0 and str(bin(x))[2:] or "-" + str(bin(x))[3:]
  4.  
  5. def floattoBinary64t(value):
  6. val = struct.unpack('Q', struct.pack('d', value))[0]
  7. return getBin(val)
  8.  
  9.  
  10.  
  11. print('Program obliczający wartość liczby zmiennoprzecinkowej w standardzie IEEE754\n')
  12.  
  13.  
  14. numb = float(input('Podaj liczbę : '))
  15.  
  16. # liczba zmiennoprzecinkowa na liczbę binarną
  17. binstr = floattoBinary64t(numb)
  18. print("Binarna wartość liczby "), numb
  19. print(binstr + '\n')
  20.  
  21. print('Wykonał Grzegorz Paradowski Z506')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement