Re: [問題] C 判斷式的寫法

看板C_and_CPP (C/C++)作者 (宅爸爸)時間12年前 (2013/12/31 13:28), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《showken (梟仔)》之銘言: : 小弟最近在寫TI DSP 2808的晶片程式,遇到如下問題想請教各位 : struct 16bits : { : unsigned int cyan :1; //bit 0 : unsigned int yellow :1; //bit 1 : ... : unsigned int black :1; //bit 15 : }; : union colorData : { : unsigned int colorBuf; : struct 16bits colorbits; : }; : ------------------------------------------------------ : union colorData myColor; : dosomething... : dosomething... : dosomething... : if (myColor.colorBuf & 0x0003) <==== : { : printf("green"); : } : ------------------------------------------------------- : 想請教大家一下,若是我以後想修改最上面結構bit的位置, : 譬如bit0跟bit15互換,但又不想每次修改的時候 : 都去修改箭頭所指的if判斷式,除了下列 : if (myColor.colorbits.cyan && myColor.colorbits.yellow) : 這樣寫以外,還有什麼其他的方法嗎? #define COLOR_CYAN 0x01 #define COLOR_YELLOW 0x02 ... #define COLOR_BLACK 0x80 #define COLOR_GREEN (COLOR_CYAN | COLOR_YELLOW) // green是不是cyan跟yellow的混色? unsigned int myColor; if (colorBuf == COLOR_GREEN) // & 改成 == { printf("green"); } 是這樣嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 134.122.249.1
文章代碼(AID): #1ImbNauF (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1ImbNauF (C_and_CPP)