Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
binary integer confusion
#11
int() and float() can read valid str and bytes to convert them. The str-Method strip is not required because int and float ignores tailing and leading whitespace.


Valid code:
print(int("\n\r\n\t      12               \t\n "))  # from str
print(int(b"\n\r\n\t      12               \t\n ")) # from bytes

print(float("\n\r\n\t      12.1337               \t\n "))  # from str
print(float(b"\n\r\n\t      12.1337               \t\n "))  # from bytes
Output:
12 12 12.1337 12.1337
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hex file to binary or pcap to binary baran01 1 5,630 Dec-11-2019, 10:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020