c# - BitConverter.DoubleToInt64Bits equivalent in python -
I really understand the best way to feel about double exact numbers, play a bit with them, and One of the things I want to do is to see their (almost) binary representation, in C #, the function The problem is that I do not seem to be able to find equivalent function in Python, is there a way to do the same things in a Thank you. Edit: The was used in the suggested answer. In the form of hexlif (struct.pack ('d', 123.456) Returns ' I get a completely different number: How about using more? UPDATE > & Lt; , BitConverter.DoubleToInt64Bits is very useful because (after converting to hexadecimal ) I want to say "real" of the temporary point number Puts a look at Riti.
BitConverter.DoubleToInt64Bits a python function?
inascii.hexlify (struct.pack (', D', 123.456))
77be 9f1a2fdd5e40' , but if I run the code that should be equal in C #, i.e.
BitConverter.DoubleToInt64Bits (123.456) .ostring (" X ")
" 405EDD2F1A 9FBE77 " .w I have made my mistake here?
& gt; & gt; import Basics>> gt; & gt; In Structure.pack ('d', 0.0) 'Structure.pack' in Structure.p;> \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 '> > Binascii '0000000000000000' & gt; Binascii.hexlify (struct.pack ('d', 1.0)) '000000000000f03f' & gt; & gt; d <<> code < Code> c type (8 bytes = 64 bits) for other formats,
@ ,
= ,
by specifying
& gt; ,
! As the first letter in the format, you can point to the byte sequence ()
& gt; & Gt; & Gt; Binascii.hexlify (struct.pack ('& lt; d', 123.456)) # Small-Endian '77be 9f1a2fdd5e40' & gt; & Gt; & Gt; Binascii.hexlify (struct.pack ('> D', 123.456) # Big-endian '405edd2f1a9fbe77'
Comments
Post a Comment