- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
#include <iostream>
#include <string>
using namespace std;
struct A
{
uint16_t n;
uint8_t a1:1;
uint8_t a2:1;
uint8_t a3:1;
uint8_t a4:1;
uint8_t a5:4;
uint8_t b;
} __attribute__((packed));
int main()
{
char v[] = { 0x1, 0x1, 0b01010011, 0x9 };
A *p = (A*)v;
cout << (uint16_t)p->a1 << endl;
cout << (uint16_t)p->a2 << endl;
cout << (uint16_t)p->a3 << endl;
cout << (uint16_t)p->a4 << endl;
cout << (uint16_t)p->a5 << endl;
cout << (uint16_t)p->b << endl;
}