Hướng dẫn python ieee 754 hex to float - python ieee 754 hex to float

Theo phỏng đoán, mỗi chuỗi HEX chứa hai giá trị dấu phẩy động chính xác đơn, không phải một và 8 ban đầu là một phần của bất kỳ giao thức tin nhắn nào đang được sử dụng, và không phải là một phần của một trong hai phao đó. Với dự đoán đó, tôi nhận được một số con số trông hợp lý:

>>> struct.unpack('>ff', binascii.unhexlify('436d4ccd436d3333'))
(237.3000030517578, 237.1999969482422)
>>> struct.unpack('>ff', binascii.unhexlify('436d999a436e0000'))
(237.60000610351562, 238.0)

Và để củng cố tính hợp lý, đây là những gì tôi nhận được bằng cách mã hóa các giá trị điểm số 1 chữ số tương ứng::

>>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
b'436d4ccd436d3333'
>>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
b'436d999a436e0000'

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
    Given a floating point number, the task is to find the hexadecimal representation for the number by IEEE 754 standard.
    The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation which was established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found in the diverse floating point implementations that made them difficult to use reliably and reduced their portability. IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based PC’s, Macs, and most Unix platforms. 
     

    Hướng dẫn python ieee 754 hex to float - python ieee 754 hex to float

    Bàn luận
     

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666

    Điều kiện tiên quyết: Số điểm nổi tiêu chuẩn 754 của IEEE, một số điểm nổi, nhiệm vụ là tìm biểu diễn thập lục phân cho số của IEEE 754 Standard. Tiêu chuẩn IEEE cho số học nổi (IEEE 754) được thành lập vào năm 1985 bởi Viện Kỹ sư Điện và Điện tử (IEEE). Tiêu chuẩn giải quyết nhiều vấn đề được tìm thấy trong các triển khai điểm nổi đa dạng khiến chúng khó sử dụng một cách đáng tin cậy và giảm tính di động của chúng. Điểm nổi tiêu chuẩn 754 của IEEE là đại diện phổ biến nhất hiện nay đối với các số thực trên máy tính, bao gồm PC, MACS, MACS và hầu hết các nền tảng Unix. & NBSP; & NBSP; 
     

    • Ví dụ: & nbsp; & nbsp;
    • Cách tiếp cận: & nbsp; & nbsp;
    • Kiểm tra xem số là dương hay âm. Lưu dấu là 0 cho dương và 1 cho âm, sau đó chuyển đổi số thành dương nếu nó âm.
    • Chuyển đổi số điểm nổi thành nhị phân.
    • Tách phần thập phân và toàn bộ phần số.
    • Tính toán số mũ (e) và chuyển đổi nó thành nhị phân.
    • Tìm Mantissa.

    Concatenate dấu hiệu của mantissa, số mũ và mantissa.
     

    Python3

    Chuyển đổi nó thành thập lục phân.

    Hãy để viết một chương trình Python để thể hiện một số nổi là HexAdecimal của IEEE 754 Standard. & NBSP; & NBSP;

    def float_bin(my_number, places = 3):

        ____1010

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    2
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    3
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    5

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    7=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    9
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    0

        

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    22=
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    2
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    4
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    7
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    8
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    9
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    4818283

        85 8687 8889

    def0def1=

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    2
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    4def5
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    5
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    9__12

    def0float_bin(my_number, places 1= float_bin(my_number, places 3 float_bin(my_number, places 4

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    4float_bin(my_number, places 6def9float_bin(my_number, places 8float_bin(my_number, places 9
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    5

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    0____6 =4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    5

    def0

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    2
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    9= 31

        33 34

    def 36

        38= ):0

        ):2 ):3):0 ):5

    def038= ):9

    def0    1=     1float_bin(my_number, places 8

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    4    6):9
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    5

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    00__
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    02

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    04=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    06=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    08

        ):2

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    23

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    04=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    27
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    29

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    16    6= ):9

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    04=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    27
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    4
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    29

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    16    6= ):9

    def0

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    10    6= ):9

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    41
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    42

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    55=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    57
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    9):9
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    60

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    62=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    10    6
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    66

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    68=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    62
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    9
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    72

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    68=
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    7
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    77
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    7883

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    55=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    83):0):5
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    86
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    87

        

    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    89=
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    2
    >>> binascii.hexlify(struct.pack('>ff', 237.3, 237.2))
    b'436d4ccd436d3333'
    >>> binascii.hexlify(struct.pack('>ff', 237.6, 238.0))
    b'436d999a436e0000'
    
    92______

        

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    00=
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    02 float_bin(my_number, places 4
    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    04__

        33

    Input :  -6744.90
    Output :  C5D2C733
    
    Input :  -263.3
    Output :  C383A666
    20


    Python có thể chuyển đổi hex thành thập phân?

    Phương pháp 1: Chuyển đổi thập lục phân sang thập phân trong python bằng int () hàm python int () này có thể được sử dụng để thực hiện nhiệm vụ cụ thể này, thêm một đối sốSố nguyên cùng một lúc.using int() This Python int() function can be used to perform this particular task, adding an argument (16) this function can convert a hexadecimal string number to base sixteen and convert it into an integer at the same time.

    Python có sử dụng IEEE 754 không?

    Python có sử dụng IEEE 754 không?Python sử dụng lớp float để thể hiện số thực.Cpython thực hiện float bằng cách sử dụng loại c kép.Loại C kép thường thực hiện phao nhị phân hai điểm chính xác của IEEE 754, còn được gọi là nhị phân64.Python uses the float class to represent real numbers. CPython implements float using C double type. The C double type usually implements IEEE 754 double-precision binary float, which is also called binary64.

    Làm thế nào để bạn chuyển đổi thập lục phân sang Python?

    Khi biểu thị số thập lục phân trong Python, tiền tố các số có '0x'.prefix the numbers with '0x'.

    Python có hỗ trợ thập lục phân không?

    Hàm python hex () hàm hex () chuyển đổi số được chỉ định thành giá trị thập lục phân.Chuỗi trả về luôn bắt đầu với tiền tố 0x.The hex() function converts the specified number into a hexadecimal value. The returned string always starts with the prefix 0x .