5 static const uint16_t uchar_s = UCHAR_MAX + 1;
7 extern uint16_t read_uint16_bigendian(FILE * file) {
8 // Read uint16 from file in big-endian order.
9 unsigned char a = fgetc(file);
10 unsigned char b = fgetc(file);
11 return (a * uchar_s) + b; }
13 extern void write_uint16_bigendian(uint16_t x, FILE * file) {
14 // Write uint16 to file in beg-endian order.
15 unsigned char a = x / uchar_s;
16 unsigned char b = x % uchar_s;
20 extern uint32_t read_uint32_bigendian(FILE * file) {
21 // Read uint32 from file in big-endian order.
22 unsigned char a = fgetc(file);
23 unsigned char b = fgetc(file);
24 unsigned char c = fgetc(file);
25 unsigned char d = fgetc(file);
26 return (a * uchar_s * uchar_s * uchar_s) + (b * uchar_s * uchar_s) + (c * uchar_s) + d; }
28 extern void write_uint32_bigendian(uint32_t x, FILE * file) {
29 // Write uint32 to file in beg-endian order.
30 unsigned char a = x / (uchar_s * uchar_s * uchar_s);
31 unsigned char b = (x - (a * uchar_s * uchar_s * uchar_s)) / (uchar_s * uchar_s);
32 unsigned char c = (x - ((a * uchar_s * uchar_s * uchar_s) + (b * uchar_s * uchar_s))) / uchar_s;
33 unsigned char d = x % uchar_s;