noninterleaved
Senior member
I am trying to read a binary file using c or c++ and store the bytes into an int. Here is what I am trying to do...
#define BUFF_SIZE sizeof(int)
char buffer[BUFF_SIZE];
int i;
int binNumber;
hFile = _open(fileName, _O_BINARY);
// read the file little-endian style for x86 architecture
for(i = 1; i <= BUFF_SIZE; i++)
{ read(hFile, &buff[BUFF_SIZE - i], 1); }
// now try to convert the bytes to an int (here is the trouble!!)
binNumber = * (int *)(buff)
now the binNumber never comes out right... anyone know what is wrong??
I am trying to read binary files from a SOLARIS/SpARC machine, that is why I have to flip all the bits backwards like that... I think the problem is in the cast... Anyone who has any experience doing this know the solution??? Thanks!!
#define BUFF_SIZE sizeof(int)
char buffer[BUFF_SIZE];
int i;
int binNumber;
hFile = _open(fileName, _O_BINARY);
// read the file little-endian style for x86 architecture
for(i = 1; i <= BUFF_SIZE; i++)
{ read(hFile, &buff[BUFF_SIZE - i], 1); }
// now try to convert the bytes to an int (here is the trouble!!)
binNumber = * (int *)(buff)
now the binNumber never comes out right... anyone know what is wrong??
I am trying to read binary files from a SOLARIS/SpARC machine, that is why I have to flip all the bits backwards like that... I think the problem is in the cast... Anyone who has any experience doing this know the solution??? Thanks!!