Aug-31-2020, 06:21 AM
(Aug-31-2020, 04:46 AM)Aussie Wrote: Hi, how do I convert byte into a binary string or int32 of same format?
01011111000110000110010100111010
Thanks,
The previous one showed how to print it as an int32. Just use bin() to print it in binary format. I don't know what "int32 of the same format" means.
>>> struct.unpack('>i', byte)[0] # as int 1121643973 >>> bin(struct.unpack('>i', byte)[0]) # as binary '0b1000010110110101110110111000101' >>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(struct.unpack('>i', byte)[0])) # as time '2005-07-17 16:46:13'