Binary comprehensions again.

Bob Cowdery <>
Fri Mar 18 22:33:26 CET 2011


Hi
This is another part of my code that works well and is pretty efficient
(thanks to help from the list).

<< <<(I/?S):32/float, (Q/?S):32/float>> || <<I:24/big-signed,
Q:24/big-signed, _M:16/big-signed>> <= Bin >>

I now need to do the same kind of thing in reverse.
This is not correct code, it won't even compile but it illustrates the
logic I want.

<< <<L:16/big-signed, R:16/big-signed, I:16, Q:16>> ||
<<round(L*?M):32/float, round(R*?M):32/float, I:0, Q:0>> <= Bin >>.

There are several problems in here and I don't know if the solution can
be quite this concise. The input binary is a sequence of two floats
which are value +1 to -1. M is a scale factor (2 bsl 15) - 1 which gives
a value that fits in a signed 16 bit integer. The output needs to be 4
integers where the last two are just padding for the present. I don't
know how to do that so I bound the variables to zero bits. It does not
seem to like the function call in there but I need to do the equivalent
of a cast somehow.

Any hints on how to form that correctly would be appreciated.

Bob


More information about the erlang-questions mailing list