Decoding an extravagant binary format 46 06 09 21 43 65 87 F9
Scott Ribe
scott_ribe@REDACTED
Mon Jul 13 18:52:52 CEST 2020
> On Jul 13, 2020, at 10:46 AM, Papa Tana <papa.tana101@REDACTED> wrote:
>
> Hi All,
>
> I receive binaries in my application:
>
> IMSI_CODED in hex_dump
> 0000 46 06 09 21 43 65 87 F9
>
> In reality, the peer is sending me this IMSI : (64 60 90 12 34 56 78 9F).
>
> I hard-decode this IMSI_CODED like below:
>
> <<R1:8, R2:8, R3:8, R4:8, R5:8, R6:8, R7:8, R8:8>> = <<IMSI_CODED:64>>,
>
> Elements = [
> string:right(integer_to_list(R1,16), 2, $0),
> string:right(integer_to_list(R2,16), 2, $0),
> string:right(integer_to_list(R3,16), 2, $0),
> string:right(integer_to_list(R4,16), 2, $0),
> string:right(integer_to_list(R5,16), 2, $0),
> string:right(integer_to_list(R6,16), 2, $0),
> string:right(integer_to_list(R7,16), 2, $0),
> string:right(integer_to_list(R8,16), 2, $0)
> ],
> R = [[B,A] || [A,B] <-Elements ], %% here, I need to revert each element :-/
> L = list_to_tuple(R),
> Z = tuple_to_list(L),
> Real_IMSI = string:join(Z,"")
>
>
> => Real_IMSI = "646090123456789F"
>
> I'm using the same hard-coding style to decode some SMS payload in
> binary format..
>
> But I can feel that there is a much more elegant way to do it, because
> as you can see, despite it's working, it's really dirty etc...
>
> Can anyone advice please?
>
> Thanks,
>
> Best Regards,
Match on 4-bit values and put them in order?
More information about the erlang-questions
mailing list