Name: Anonymous 2012-06-09 22:22
Alright so what I'm trying to do is read the data chunks from a .WAV file and convert each chunk to decimal (0 - 65535 was the original range) so that I can manipulate it and use it with my micro controller. Anyway, I'm using fstream and reading the entire contents to a memory block, then unloading the file and transferring data from the memory block to the new file. There only seems to be one problem, the strtol function is not converting the hex data to decimal. I believe it may be because the hex data is being read as ASCII rather than hex values, i.e. ÷¾ instead of f7be. This is the code I am using to process the data.
for (int i=44; i<dloop; i=i+2)
{
// Prepare hex values
temp[0] = memblock[i+1];
temp[1] = memblock[i];
temp[2] = 0;
// Convert hex to dec
conv = strtol(temp,&pEnd,16);
save << temp << " " << conv << "\n";
}
It outputs the raw hex code then puts a space, then outputs the converted decimal values. This is the output.
ök 0
÷ 0
÷¾ 0
ø+ 0
øT 0
etc
Any suggestions? Also the reversing of the hex bytes before converting is intentional.
for (int i=44; i<dloop; i=i+2)
{
// Prepare hex values
temp[0] = memblock[i+1];
temp[1] = memblock[i];
temp[2] = 0;
// Convert hex to dec
conv = strtol(temp,&pEnd,16);
save << temp << " " << conv << "\n";
}
It outputs the raw hex code then puts a space, then outputs the converted decimal values. This is the output.
ök 0
÷ 0
÷¾ 0
ø+ 0
øT 0
etc
Any suggestions? Also the reversing of the hex bytes before converting is intentional.