[問題] int 4 bits
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
問題(Question):
想要宣告一個4bits的正整數,
存放範圍 0~15
不曉得這樣的宣告方式正不正確?
struct {
unsigned int boy : 4;
unsigned int girl : 4;
} age;
不曉得這樣是不是
boy 4 bits
girl 4 bits
我看網路資料他的參考Example是
struct {
unsigned int widthValidated : 1;
unsigned int heightValidated : 1;
} status;
The above structure requires 4 bytes of memory space for status variable, but
only 2 bits will be used to store the values.
宣告4 bytes 但是只有2 bits會存放到memory
感謝大大幫忙!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.89.77
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1466561627.A.057.html
※ 編輯: hardware (140.117.89.77), 06/22/2016 10:17:56
→
06/22 10:25, , 1F
06/22 10:25, 1F
→
06/22 10:26, , 2F
06/22 10:26, 2F
推
06/22 10:28, , 3F
06/22 10:28, 3F
→
06/22 10:28, , 4F
06/22 10:28, 4F
→
06/22 10:31, , 5F
06/22 10:31, 5F
→
06/22 10:33, , 6F
06/22 10:33, 6F
→
06/22 10:44, , 7F
06/22 10:44, 7F
推
06/22 12:30, , 8F
06/22 12:30, 8F
→
06/22 12:30, , 9F
06/22 12:30, 9F
→
06/22 12:41, , 10F
06/22 12:41, 10F
→
06/22 12:42, , 11F
06/22 12:42, 11F
→
06/22 12:43, , 12F
06/22 12:43, 12F
推
06/22 14:57, , 13F
06/22 14:57, 13F
→
06/22 14:57, , 14F
06/22 14:57, 14F
→
06/22 15:02, , 15F
06/22 15:02, 15F
推
06/22 16:37, , 16F
06/22 16:37, 16F
→
06/22 16:37, , 17F
06/22 16:37, 17F
推
06/22 19:24, , 18F
06/22 19:24, 18F
推
06/22 20:41, , 19F
06/22 20:41, 19F
推
06/23 11:00, , 20F
06/23 11:00, 20F
→
06/23 11:01, , 21F
06/23 11:01, 21F
→
06/23 11:01, , 22F
06/23 11:01, 22F