This question appeared maybe an hour ago, but was removed by OP. I'm still interested in a solution. Suppose we have a text file with hex numbers separated by tabs (or spaces):
000F 6D30 5800 4680 3790 2910 1B50 0DB0
02E0 F6F0 ED20 E7A0 E6D0 1240 3490 4E50
6700 7670 7B60 6480 5140 4120 3100 23A0
14D0 0B60 FCA0 F2D0 E990 E670 E880 20B0
3F20 56E0 6C00 7C90 72B0 5C90 4A20 3B70
2C40 1E30 1140 0500 F960 EF10 E890 E620
And we want to get a 2D List
of integers.
Is there some sort of format specifier we can add to Import
?
I tried a straightforward solution and it works, but looks over-complicated:
importTable[fileName_, separator_] :=
Map[FromDigits[#, 16] &,
ToExpression /@ (# /. {"A" -> 10, "B" -> 11, "C" -> 12,
"D" -> 13, "E" -> 14, "F" -> 15}) & /@
Characters /@ StringSplit[#, separator], 1] & /@
Import[fileName, "Lines"];
Using importTable["test.dat", WhitespaceCharacter ..]
will parse the above.
Is there a "native" way of doing it?
Map[FromDigits[#, 16] &]@*StringSplit /@ Import[file, "Lines"]
$\endgroup$ – C. E. Jun 24 '15 at 19:37Map[FromDigits[#, 16] &, Import["test.dat", "Table", "Numeric" -> False], {2}]
, but the original thread got deleted. $\endgroup$ – J. M.'s ennui♦ Jun 24 '15 at 19:51"Numeric" -> False
is it documented anywhere? $\endgroup$ – BlacKow Jun 24 '15 at 20:00"Table"
format, IIRC. $\endgroup$ – J. M.'s ennui♦ Jun 24 '15 at 20:01