Store 4 different values in a byte

前端 未结 3 1451
忘了有多久
忘了有多久 2021-01-25 01:32

I have an assignment to do, but I have no clue where to start. I am not expecting and definitely do not want answers in code. I would like some guidance as in what to do because

3条回答
  •  不知归路
    2021-01-25 01:42

    Have you read about bit field?

    struct s {
      unsigned char engine_on : 1;
      unsigned char gear_pos : 3;
      unsigned char key_pos : 2;
      unsigned char brake1 : 1;
      unsigned char brake2 : 1;
    };
    

提交回复
热议问题