[erlang-questions] Re. How to decode octet to septets using erlang (prasantha kumara)

Tony Seebregts tony.seebregts@REDACTED
Thu Mar 5 12:31:07 CET 2009


This is an extract from the code I use:

> unpack(UD) ->
>    septets(list_to_binary([ flip(X) || X <- binary_to_list(UD) ])).
>
> septets(T) ->
>     [ flipx(X) || <<X:7>> <= T].
>
> % Flips the bits in an octet/septet for easy unpacking
>
> flip(Octet) ->
>    <<B8:1,B7:1,B6:1,B5:1,B4:1,B3:1,B2:1,B1:1>>  = <<Octet>>,
>    <<B1:1,B2:1,B3:1,B4:1,B5:1,B6:1,B7:1,B8:1>>.
>

There is probably a better way of doing it but I was in a rush at the time
:-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090305/1d3141c0/attachment.htm>


More information about the erlang-questions mailing list