Decimal to binary Half-Precision IEEE 754 in Python

Kaio

I was only able to convert a decimal into a binary single-precision IEEE754, using the struct.pack module, or do the opposite (float16 or float32) using numpy.frombuffer

Is it possible to convert a decimal to a binary half precision floating point, using Numpy?

I need to print the result of the conversion, so if I type "117.0", it should print "0101011101010000"

jfs

if I type "117.0", it should print "0101011101010000"

>>> import numpy as np
>>> bin(np.float16(117.0).view('H'))[2:].zfill(16)
'0101011101010000'

.view('H') reinterprets the memory occupied by the float16 value as an unsigned integer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

IEEE 754 Denormalized Decimal Converting to Half-Point Binary

Convert a binary string into IEEE-754 single precision - Python

Converting Decimal to Single-Precision IEEE 754

Round to IEEE 754 precision but keep binary format

IEEE754 single precision - General algorithm for representing the half of a number

Python generate IEEE 754 double-precision binary floating-point format

Converting IEEE-754 double and single precision to decimal Java bug

IEEE 754 to decimal

How to convert decimal to IEEE double precision floating point binary in Matlab?

Double Conversion to decimal value IEEE-754 in Python

How do I convert a hexadecimal number in IEEE 754 double precision (64bit) format to a decimal number?

String of float to IEEE 754 binary128 in Python

float.h-like definitions for IEEE 754 binary16 half floats

IEEE-754 Python

converting decimal to IEEE-754 format

Python program to convert Hexadecimal to IEEE-754 Floating Point with Single precision

on what systems does Python not use IEEE-754 double precision floats

Float to binary conversion in C(ieee 754)

IEEE 754: can casting before division cause loss of precision?

Why number are (not) representable in double precision IEEE754?

Do javascript numbers follow IEEE 754 double precision?

Accuracy of data type float (IEEE 754 Single-precision)

How to normalize the sum of two IEEE754 single precision numbers?

Hexadecimal to float IEEE 754 double precision c++

Converting a decimal number to floating point notation and IEEE 754 format

Equation to convert IEEE754 to decimal (normalised form)

Decimal to half-precision floating point

IEEE 754 binary floating-point numbers imprecise for money

Is hardcode float precise if it can be represented by binary format in IEEE 754?