可进一步优化:
Binary = <<"2345", 1, "restofmessageexistshere">>
get_integer_value(Binary) ->
[Num, _, LastRest] = integer_value(Binary),
[Num, LastRest].
integer_value(<<1, _Rest/binary>>) -> [0, 1, _Rest];
integer_value(<<H:8, Rest/binary>>) ->
% io:format("~n~p~n", [Rest]),
[Num, Exp, LastRest] = integer_value(Rest),
[(H-48)*Exp + Num, Exp*10, LastRest].
Expected Result -> [2345, "restofmessageexistshere"]