CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hex Hassle Please Please Help!



I am currently writing a program to create a wave file (*.wav) from a
number of given data values. Data is given in the range +32767 to -32767
and sent to a file. The data in the file is in the format 0x??,etc.
The following source code seems to work, but there is a big problem with
it.
	short v;
	char buf[2];
	buf[0]=v&0xFF;
	buf[1]=(v>>8)&0xFF;
	file.write(buf,2);

If, for example v=9, the file has the data="09", if v=11, data="0B",etc
BUT, if v=10, the data seem to include a new byte, with the output as
"0D0A". This happens every time either one of the bytes goes to "0A",
but not at any other time. 

If anyone knows why this is, I would be VERY grateful if you could let
me know, and whether or not there is a solution.

Many thanks,
Richard Buckley


W Komornicki's Home Page | Main Index | Thread Index