久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

獲取“位";Python中的浮點數?

Get the quot;bitsquot; of a float in Python?(獲取“位;Python中的浮點數?)
本文介紹了獲取“位";Python中的浮點數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找與 Java 的 Float.floatToBits 等效的 Python.

I am looking for the Python equivalent of Java's Float.floatToBits.

我發現了這個 Python:獲取 &操縱(作為整數)浮點數的位模式,但有人知道不那么復雜的方法嗎?

I found this Python: obtain & manipulate (as integers) bit patterns of floats but does anyone know of a less complicated way?

推薦答案

Alex Martelli 在該問題中給出的答案非常簡單——您可以將其簡化為:

The answer that Alex Martelli gives in that question is really pretty simple -- you can reduce it to:

>>> import struct
>>> 
>>> 
>>> def floatToBits(f):
...     s = struct.pack('>f', f)
...     return struct.unpack('>l', s)[0]
...     
... 
>>> floatToBits(173.3125)
1127043072
>>> hex(_)
'0x432d5000'

一旦你將它作為一個整數,你可以執行任何其他你需要的操作.

Once you have it as an integer, you can perform any other manipulations you need to.

您可以將操作順序顛倒為往返:

You can reverse the order of operations to round-trip:

>>> def bitsToFloat(b):
...     s = struct.pack('>l', b)
...     return struct.unpack('>f', s)[0]

>>> bitsToFloat(0x432d5000)
173.3125

這篇關于獲取“位";Python中的浮點數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標)
主站蜘蛛池模板: 日本久久视频 | 欧美一区二区免费 | 成人久久18免费网站 | 精品一二三区 | 国产精品99久久久久久动医院 | www.久久久久久久久久久久 | 亚洲精品99久久久久久 | 欧美成人a | 精品无码久久久久国产 | 日韩中文字幕一区二区 | 精品国产一区二区三区久久 | 久久99蜜桃综合影院免费观看 | 成人三级视频 | 国产精品伦理一区二区三区 | 亚洲小视频在线观看 | 91国内精品久久 | 成人免费看片又大又黄 | av久久| 国产91在线 | 中日 | 色av一区二区三区 | 日韩视频免费在线 | 夜夜草天天草 | 欧美一级片在线观看 | 金莲网| 一区二区av | 国产午夜av片 | 黄色在线免费观看 | 黄色网址在线免费播放 | 免费同性女女aaa免费网站 | 中文在线一区 | 国产特级毛片 | 成人欧美日韩一区二区三区 | 精精国产xxxx视频在线播放 | 亚洲一级在线 | 欧美.com | 国产精品视频在线观看 | 欧美精品一二三区 | a精品视频 | 成人免费视频 | 久久久精品国产 | 在线看片国产 |