73 int fwrite_be(
const int* aa,
int size,
int nb, FILE* fich) {
81 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
85 int size_tot = 4 * nb ;
87 char* bytes_big =
new char[size_tot] ;
88 char* pbig = bytes_big ;
89 const char* plit =
reinterpret_cast<const char*
>(aa) ;
91 for (
int j=0; j< nb; j++) {
93 for (
int i=0; i<4; i++) {
103 int nx = int(fwrite(bytes_big, 1, size_tot, fich) / 4) ;
105 delete [] bytes_big ;
112 return int(fwrite(aa, size, nb, fich)) ;
123 int fwrite_be(
const double* aa,
int size,
int nb, FILE* fich) {
131 bool little_endian = ( *(
reinterpret_cast<char*
>(&itest) ) == 1) ;
135 int size_tot = 8 * nb ;
137 char* bytes_big =
new char[size_tot] ;
138 char* pbig = bytes_big ;
139 const char* plit =
reinterpret_cast<const char*
>(aa) ;
141 for (
int j=0; j< nb; j++) {
143 for (
int i=0; i<8; i++) {
144 pbig[i] = plit[7-i] ;
152 int nx = int(fwrite(bytes_big, 1, size_tot, fich) / 8) ;
153 delete [] bytes_big ;
160 return int(fwrite(aa, size, nb, fich)) ;
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.