ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Воскресенье
19 мая
180827 Топик полностью
fk0, легенда (10.02.2010 11:15, просмотров: 149) ответил koyodza на кто как решает проблему преобразования BigEndian <-> LittleEndian?
Она решается наличием endian.h, BYTE_ORDER, и чем-то вроде такого:  #include <endian.h> #if (BYTE_ORDER == LITTLE_ENDIAN) #define GET_LE16(ptr) (*(uint16_t*)(ptr)) #define GET_LE32(ptr) (*(uint32_t*)(ptr)) #define PUT_LE16(ptr, val) (*(uint16_t*)(ptr)=(val)) #define PUT_LE32(ptr, val) (*(uint32_t*)(ptr)=(val)) #else #if (BYTE_ORDER == BIG_ENDIAN) /* BIG_ENDIAN machine */ #define GET_LE16(ptr) ( ((uint8_t*)ptr)[0] | ((uint8_t*)ptr)[1]<<8 ) #define GET_LE32(ptr) ( \ ((uint8_t*)ptr)[0] | ((uint8_t*)ptr)[1]<<8 \ | (uint32_t)((uint8_t*)ptr)[2]<<16 | (uint32_t)((uint8_t*)ptr)[3]<<24 ) #define PUT_LE16(ptr, val) do { \ uint16_t __t = (val); \ ((uint8_t*)ptr)[0]=__t&0xff, ((uint8_t*)ptr)[1]=(__t>>8)&0xff; \ } while(0) #define PUT_LE32(ptr, val) do { \ uint32_t __t = (val); \ ((uint8_t*)ptr)[0]=__t&0xff, ((uint8_t*)ptr)[1]=(__t>>8)&0xff, \ ((uint8_t*)ptr)[2]=(__t>>16)&0xff, ((uint8_t*)ptr)[3]=(__t>>24)&0xff; \ } while(0) #else #error undefined endianess! #endif #endif BYTE_ORDER := LITTLE_ENDIAN | BIG_ENDIAN LITTLE_ENDIAN := 1234 BIG_ENDIAN := 4321
[ZX]