# Float to int bits

**URL:** <https://discourse.nodered.org/t/float-to-int-bits/26281>\
**Category:** General\
**Created:** [8 May 2020 04:32 UTC](https://discourse.nodered.org/t/float-to-int-bits/26281 "2020-05-08T04:32:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![slogan87](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/slogan87/32/22366_2.png) [@slogan87](https://discourse.nodered.org/u/slogan87)\
**Post date:** [8 May 2020 04:32 UTC](https://discourse.nodered.org/t/float-to-int-bits/26281/1 "2020-05-08T04:32:41Z")

</div>

HI everyone,

I was wondering if I could please get some help. I am trying to convert a floating value to individual bits so I can convert it to 2 16 bit registers to send through modbus to a plc.

I have been trying to use all sorts of function and this is what I have so far.

> Blockquote

test = msg.payload;  
f = Float.floatToIntBits(test);  
msg.payload = f;  
return msg;

> Blockquote

It does not seem to be working.  
I am getting this error ReferenceError: Float is not defined (line 2, col 1)

Kind Regards  
Sam

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 May 2020 08:28 UTC](https://discourse.nodered.org/t/float-to-int-bits/26281/2 "2020-05-08T08:28:42Z")

</div>

> [@slogan87](#):
>
> Float.floatToIntBits(test)

That is Java not JavaScript.

Use a function node and the [Buffer](https://nodejs.org/api/buffer.html) object

Use the write float function to add your value then read 2 integers out.

---

<div class="post-metadata">

**Author:** ![slogan87](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/slogan87/32/22366_2.png) [@slogan87](https://discourse.nodered.org/u/slogan87)\
**Post date:** [8 May 2020 22:38 UTC](https://discourse.nodered.org/t/float-to-int-bits/26281/3 "2020-05-08T22:38:56Z")

</div>

Hi Steve,

Thanks for pointing me in the right direction. Coding is new to me but generally I can follow instructions. Works a treat.

Regards  
Sam

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 May 2020 22:39 UTC](https://discourse.nodered.org/t/float-to-int-bits/26281/4 "2020-05-22T22:39:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
