From array a of n bytes, build the equivalent hex string s of 2n digits. Each byte (256 possible values) is encoded as two hexadecimal characters (16 possible values per digit).
hexChar(Num) when Num < 10 andalso Num >= 0->
$0 + Num;
hexChar(Num) when Num < 16 ->
$a + Num - 10.
toHex([Byte | Rest]) ->
[hexChar(Byte div 16), hexChar(Byte rem 16)] ++ toHex(Rest);
toHex([]) -> [].
use iso_c_binding, only : c_int8_t
character(len=:), allocatable :: s
allocate (character(len=2*size(a)) :: s)
write(unit=s,fmt='(*(Z2.2))') a
hexChar(Num) when Num < 10 andalso Num >= 0->
$0 + Num;
hexChar(Num) when Num < 16 ->
$a + Num - 10.
toHex([Byte | Rest]) ->
[hexChar(Byte div 16), hexChar(Byte rem 16)] ++ toHex(Rest);
toHex([]) -> [].