2
$\begingroup$
testList = {1, 2, 3, 4};
file = "test1";
BinaryWrite[file, testList];
BinaryReadList[file]
Close[file];

Gives

{1, 2, 3, 4}

Cool... but

testList = {1, 2, 3, -4};
file = "test1";
BinaryWrite[file, testList];
BinaryReadList[file]
Close[file];

Results in

BinaryWrite::nocoerce: -4 cannot be coerced to the specified format. >>

I have to Read and Write Data files that are 5GB large and they have pos and negativ values. Is there a work around?

$\endgroup$
4
$\begingroup$

The default type is an unsigned integer. You need to specify a suitable type, eg:

testList = {1, 2, 3, -4};
file = "test1";
BinaryWrite[file, testList, "Integer8"];
BinaryReadList[file, "Integer8"]
Close[file];

Note the read needs to know the type as well. See BinaryRead for the list of types. (Integer8 is only good for values in the range -128 to 127 of course )

$\endgroup$
  • $\begingroup$ Do you know whats the identifier for double? $\endgroup$ – newandlost Jul 14 '15 at 14:58
  • $\begingroup$ Just found it... "Real64" Thanks! $\endgroup$ – newandlost Jul 14 '15 at 14:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.