4y4z, есть еще один нюанс - порядок байт и порядок компоновки бит. Физическое представление и описание на Си могут различаться.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct full_entry
{
unsigned int entry_type:2;
unsigned int sats_number:4;
unsigned int gps_fix:1;
unsigned int ext_data:1;
unsigned int speed:7;
unsigned int unused_data:3;
unsigned int utc_time:30;
unsigned int xpos:24;
unsigned int ypos:24;
unsigned int zpos:24;
} __attribute__ ((packed));
int main()
{
struct full_entry t;
unsigned char *p;
int n, b;
printf("Size: %u\n", sizeof(struct full_entry));
memset((void*)&t, 0, sizeof(struct full_entry));
t.entry_type = 3;
t.gps_fix = 1;
t.speed = 0x7f;
t.utc_time = 0x3fAAAAff;
t.ypos = 0xAAff55;
p = (unsigned char*)(void*)&t;
printf("Bits:\n 7 6 5 4 3 2 1 0\n");
for (n = 0; n < sizeof(struct full_entry); n++)
{
printf(" %02u:", n);
for (b = 0; b < 8; b++)
printf(" %u", 1 & (p[n] >> (7 - b)));
printf(" (0x%02x)\n", p[n]);
}
printf("\n");
return 0;
}
gcc -Wall -o t1 t1.c
Size: 15
Bits:
7 6 5 4 3 2 1 0
00: 0 1 0 0 0 0 1 1 (0x43)
01: 0 1 1 1 1 1 1 1 (0x7f)
02: 1 1 1 1 1 1 0 0 (0xfc)
03: 1 0 1 0 1 0 1 1 (0xab)
04: 1 0 1 0 1 0 1 0 (0xaa)
05: 1 1 1 1 1 1 1 0 (0xfe)
06: 0 0 0 0 0 0 0 0 (0x00)
07: 0 0 0 0 0 0 0 0 (0x00)
08: 0 0 0 0 0 0 0 0 (0x00)
09: 0 1 0 1 0 1 0 1 (0x55)
10: 1 1 1 1 1 1 1 1 (0xff)
11: 1 0 1 0 1 0 1 0 (0xaa)
12: 0 0 0 0 0 0 0 0 (0x00)
13: 0 0 0 0 0 0 0 0 (0x00)
14: 0 0 0 0 0 0 0 0 (0x00)
Посмотри на тестовые значения и как битовое число расположилось в памяти. Специально инициализировал поля через одно.