[erlang-questions] undefined function erlang:binary_to_float/1

Tony Rogvall tony@REDACTED
Thu Jul 18 13:31:58 CEST 2013


On 18 jul 2013, at 13:19, Schneider <js@REDACTED> wrote:

> yea, this should work. But It's looks like my Problem is a little bit more complicated:
> 
> I have a C client sending some Data via UDP. And I want to write a Erlang program receiving this data.
> 
> the Data is of the form {unsigned long, float} (both stored as 4Byte values) but the binary I receive is of the form {int, int}.
> How can i convert the second one to an erlang float?
> 

If the data is sent on the same machine without endian handling (byte order) then you can match (binary) data like:

	<<Long:32/unsigned-integer-native, Float:32/float-native>>

You can change native to 'big' or 'little' if that byte order used. Files formats and network protocol mostly select
a byte order or flag it some how in the protocol specification. 
Hint. For intel based machines little endian is used. PowerPC / M680xx are big endian.

/Tony



> bg,
> Johannes
> 
> On Wed 17 Jul 2013 04:30:45 PM CEST, Wes James wrote:
>> Alternative for now??
>> 
>> list_to_float(binary:bin_to_list(<<"10.0">>)).
>> 10.0
>> 
>> 
>> On Wed, Jul 17, 2013 at 8:02 AM, Schneider <js@REDACTED
>> <mailto:js@REDACTED>> wrote:
>> 
>>    Hi List,
>> 
>>    I cannot find the function binary_to_float/1.
>> 
>>    using Erlang R14B04 (erts-5.8.5) on ubuntu precise.
>>    What do I miss?
>> 
>>    bg,
>>    Johannes
>> 
>>    --
>>    GLOBE Development GmbH
>>    Königsberger Strasse 260
>>    48157 MünsterGLOBE Development GmbH
>>    Königsberger Strasse 260
>>    48157 Münster
>>    0251/5205 390
>> 
>>    _________________________________________________
>>    erlang-questions mailing list
>>    erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>>    http://erlang.org/mailman/__listinfo/erlang-questions
>>    <http://erlang.org/mailman/listinfo/erlang-questions>
>> 
>> 
> 
> 
> 
> --
> GLOBE Development GmbH
> Königsberger Strasse 260
> 48157 MünsterGLOBE Development GmbH
> Königsberger Strasse 260
> 48157 Münster
> 0251/5205 390
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130718/300be1d9/attachment.htm>


More information about the erlang-questions mailing list