2020-02-16 23:15:54 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
uint16_t Binary_to_MINUS_int16(uint8_t b1, uint8_t b2) {
|
2020-02-21 15:22:01 +03:00
|
|
|
return (uint16_t)(b2 << 8) | b1;
|
2020-02-16 23:15:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Binary_to_MINUS_int32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) {
|
2020-02-21 15:22:01 +03:00
|
|
|
return (uint32_t)b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
|
2020-02-16 23:15:54 +03:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:22:01 +03:00
|
|
|
uint64_t Binary_to_MINUS_int64(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4,
|
|
|
|
uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8) {
|
|
|
|
return (uint64_t)b1 | (b2 << 8) | (b3 << 16) | (b4 << 24) |
|
|
|
|
((uint64_t)b5 << 32) | ((uint64_t)b6 << 40) | ((uint64_t)b7 << 48) |
|
|
|
|
((uint64_t)b8 << 56);
|
2020-02-16 23:15:54 +03:00
|
|
|
}
|
2020-02-17 23:38:55 +03:00
|
|
|
|
2020-02-18 21:35:35 +03:00
|
|
|
uint8_t Binary_int16_MINUS_to_MINUS_byte(uint16_t *x) {
|
2020-02-21 15:22:01 +03:00
|
|
|
return *x & 0xff;
|
2020-02-18 21:35:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Binary_int32_MINUS_to_MINUS_byte(uint32_t *x) {
|
2020-02-21 15:22:01 +03:00
|
|
|
return *x & 0xff;
|
2020-02-18 21:35:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Binary_int64_MINUS_to_MINUS_byte(uint64_t *x) {
|
2020-02-21 15:22:01 +03:00
|
|
|
return *x & 0xff;
|
2020-02-18 21:35:35 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 23:38:55 +03:00
|
|
|
int Binary_system_MINUS_endianness_MINUS_internal() {
|
2020-02-21 15:22:01 +03:00
|
|
|
// The int type is always >= 16 bits, two bytes, according to The C
|
|
|
|
// Programming Language, Second Edition. Contrarily, char is always a single
|
|
|
|
// byte.
|
|
|
|
//
|
|
|
|
// Allocating 1 and converting to char will leave us with the first byte
|
|
|
|
// used to represent the int. On a little endian machine, we're left with 1
|
|
|
|
// on a big endian machine, we're left with 0.
|
|
|
|
unsigned int i = 1;
|
|
|
|
// Conversion to char lets us access bytes individually.
|
|
|
|
// We return the first byte.
|
|
|
|
return (int)((char *)&i)[0];
|
2020-02-17 23:38:55 +03:00
|
|
|
}
|