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

Hynek Vychodil vychodil.hynek@REDACTED
Thu Mar 5 13:08:39 CET 2009


Why not?

unpack(UD) ->
  << <<0:1,X/bits>> || <<X:7/bits>> <= UD >>.

2009/3/5 Tony Seebregts <tony.seebregts@REDACTED>

> 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
> :-)
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090305/df9393d6/attachment.htm>


More information about the erlang-questions mailing list