Suppose I have a binary file which consists of a list of integer or real numbers. Let's say signed 8-bit integers; so each byte of the file is a single such integer. How can I read it and turn it into a
Integer8? (without going through a
I could not find anything like that in the documentation. The closest I found is to read the file as
ByteArray and then try to use what's suggested in the last answer of
How to convert a RawArray of bytes to ByteArray?
to convert to
NumericArray. Unfortunately this only seems to work with
Byte, i.e., unsigned 8-bit integers:
test = ReadByteArray["data/set0-config"]; test2 = NumericArray[test, "Integer8"]
fails with the unhelpful error message
NumericArray::nconvsa: The argument ByteArray[...] cannot be automatically converted to a NumericArray of type Integer8. Try using one of the following conversion methods: "Round", "ClipAndCoerce" or "ClipAndRound".
(none of these methods achieve the desired result, not to mention the fact that I don't want Mathematica to rewrite the whole binary data).
Overall, I've found very little information on
NumericArray (e.g., another obvious question is whether they can be used in compiled functions).