#Erlang, ASN.1, and TBCD-STRINGs
So, maybe this post will find its way into search results…
So, maybe you're using Erlang in a Telecom setting…
So, maybe you need to work with asn1ct or asn1rt…
So, maybe you need to do something with an IMSI or IMEI that you got from decoding an ASN.1 Call Data Record, or GTP' stream… So, maybe the values look unfamiliar and you need a way to make it look like your familiar old IMSI code… So, maybe here's some code using a bit of bit syntax and tail recursion?
-module(tbcd). -export([string_decode/1]). string_decode(<<>>) -> []; string_decode(<<Nibble1:4,Nibble2:4,Rest/binary>>) -> Byte = Nibble1 bor (Nibble2 bsl 4), lists:flatten([io_lib:format("~2.16.0B", [Byte])|string_decode(Rest)]).
Here's how it does stuff:
1> c("tbcd.erl"). {ok,tbcd} 2> tbcd:string_decode(<<33,67,101,135,9,33,67,245>>). "123456789012345F" 3>













