[英]How to Convert 32 bit float value to two 16 bit integers
I have a question that How to Convert 32 bit float value to two 16 bit integers . 我有一个问题, 如何将32位浮点值转换为两个16位整数 。
Actually Im converting two 16 bits integers into 32 - bit float. 实际上,我将两个16位整数转换为32位浮点型。
from the reference of two-16-bit-ints-to-one-32-bit-float-value 从两个16位整数到一个32位浮点值的引用
But i need one 32 bit float to two 16 bit ints.Any one Help me. 但是我需要一个32位浮点数到两个16位int.Any一个人帮帮我。
Thanks In Advance 提前致谢
This would do the trick 这可以解决问题
float f = 107.5f; // the float value
int v = Float.floatToIntBits(f);
int i1 = (v >> 16) & 0xffff;
int i2 = v & 0xffff;
giving the two 16 bit quantities i1
and i2
. 给出两个16位量
i1
和i2
。
Maybe something along the lines of: 也许是这样的:
int value = Float.floatToRawIntBits(Float.valueOf("1074563458561.34").floatValue());
int value1 = value >>> 16;
int value2 = value << 16 >>> 16;
System.out.println(String.format("%d %d", value1, value2));
21370 12537
21370 12537
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.