[erlang-questions] Mystery float binary matching

Konstantin Tcepliaev f355@REDACTED
Wed Jun 27 22:17:56 CEST 2012


That'll work well with three obvious assumptions:
1. You need to match only one field and that wouldn't change in the future.
2. Your input is coming from the machine with the same endianness.
3. Erlang VM matches the Bin2 second time using pointer to binary heap and not the binary data itself (which seems quite logical, though I'm not completely sure).
If these are met, then you're good to go.

27.06.2012, 23:53, "Michael Uvarov" <freeakk@REDACTED>:
> I use this:
>
>    try
>        <<Value:native-float, Bin2/binary>> = Bin,
>        {Value, Bin2};
>     catch error:{badmatch, _Bin} ->
>         BitCount = bit_size(<<0/native-float>>),
>         <<_Skip:BitCount, Bin2/binary>> = Bin,
>         {undefined, Bin2}
>     end.



More information about the erlang-questions mailing list