[PR]

定数を2進表記で記述する

戻る

 2進数表記で定数を指定するためのマクロを作る。

	#define CONST_BINARY_0000 ( 0x0 )
	#define CONST_BINARY_0001 ( 0x1 )
	#define CONST_BINARY_0010 ( 0x2 )
	#define CONST_BINARY_0011 ( 0x3 )
	#define CONST_BINARY_0100 ( 0x4 )
	#define CONST_BINARY_0101 ( 0x5 )
	#define CONST_BINARY_0110 ( 0x6 )
	#define CONST_BINARY_0111 ( 0x7 )
	#define CONST_BINARY_1000 ( 0x8 )
	#define CONST_BINARY_1001 ( 0x9 )
	#define CONST_BINARY_1010 ( 0xA )
	#define CONST_BINARY_1011 ( 0xB )
	#define CONST_BINARY_1100 ( 0xC )
	#define CONST_BINARY_1101 ( 0xD )
	#define CONST_BINARY_1110 ( 0xE )
	#define CONST_BINARY_1111 ( 0xF )
	
	#define BIN4( a )  \
		CONST_BINARY_ ## a
	#define BIN8( a, b )  \
		((unsigned char)( ((0x0F & (BIN4( a ))) << 4) | (0x0F & (BIN4( b ))) ))
	#define BIN16( a, b, c, d )  \
		((unsigned short)( ((0xFF & (BIN8( a, b ))) << 8) | (0xFF & (BIN8( c, d ))) ))
	#define BIN32( a, b, c, d, e, f, g, h )  \
		((unsigned long)( ((0xFFFF & (BIN16( a, b, c, d ))) << 16) | (0xFFFF & (BIN16( e, f, g, h ))) ))

使用例

	const unsigned int CRC16_CCITT = BIN16( 1000,1000,0001,0000 );
	const unsigned int CRC16       = BIN16( 1100,0000,0000,0010 );
	const unsigned int CRC32       = BIN32( 1000,0010,0110,0000,1000,1110,1101,1011 );

Google
ご意見・ご感想をお聞かせ下さい。匿名で送信できます。

 * 返信が必要な場合には postmaster@katsura-kotonoha.sakura.ne.jp へ直接メールしてください。

水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
同人ダウンロード販売
同人ダウンロード販売|DL.Getchu.com