2021-11-26 BYTEデータからBITデータを取り出す ひよっこプログラマー BYTEデータからBITデータを取り出す方法 共用体を使う /* * データを格納する共用体 */union MSG_BUFFER { unsigned char BYTE; struct { unsigned int state : 4; unsigned int id : 4; } BIT;}; main(void){ union MSG_BUFFER msg; msg.BYTE = 0x1a; // test data syslog(LOG_NOTICE, " BIT.state : 0x%3X\n BIT.id : 0x%3X", msg.BIT.id, msg.BIT.state); /* 結果 * BIT.id : 0x 1 * BIT.state : 0x A */ } 参考:https://teratail.com/questions/198761 *******記事の更新記録******* 2021/11/26....初回記録!<更新! *********************