Вопрос

Is there anyway to treat as a float an int's value (and back)? Like this:

int myInt = 1729;
float myFloat = intToFloatPreservingBitPattern(myInt);
int otherInt = floatToIntPreservingBitPattern(myFloat);

(in C++ I could use float myFloat = reinterpreted_cast<float>(myInt), I'm looking for something similar in Java)

Это было полезно?

Решение

You're looking for the Float.intBitsToFloat method.

The reverse is the Float.floatToIntBits method.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top