Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Conversion from byte array to float.

Hi All,
I have a byte array of size 4 whuch should be converted to its float value.
I am able to this kind of conversion (byte array) to integer primitive but
its difficult to apply the samme..
Thanx in adv,
madhu
[238 byte] By [madhusudhan] at [2007-11-9 22:28:20]
# 1 Re: Conversion from byte array to float.
A better solution to this problem would be to create a float value in the
first place instead of creating a byte array and then trying to convert it.
However, here's an answer to your question:

DataInputStream dis = new DataInputStream(new
ByteArrayInputStream(yourByteArray));
float f = dis.readFloat();

But as I said, it would be better to use a DataInputStream and readFloat()
to create the value in the first place. And the same is true for integers.

PC2

"madhusudhan" <madhu_sri@indya.com> wrote in message
news:3b0cd07a$1@news.dev-archive.com...
>
> Hi All,
> I have a byte array of size 4 whuch should be converted to its float
value.
> I am able to this kind of conversion (byte array) to integer primitive
but
>
> its difficult to apply the samme..
> Thanx in adv,
> madhu
>
>
Paul Clapham at 2007-11-11 23:04:47 >
# 2 Re: Conversion from byte array to float.
Hi

How does the decimal portion is stored in the byte array of size 4

"madhusudhan" <madhu_sri@indya.com> wrote:
>
>Hi All,
> I have a byte array of size 4 whuch should be converted to its float value.
> I am able to this kind of conversion (byte array) to integer primitive
but
>
>its difficult to apply the samme..
>Thanx in adv,
>madhu
>
>
Rajkamal Gopinath at 2007-11-11 23:05:43 >