본문 바로가기

컴퓨터/C/C++

2008년 8월 29일 한 가지 변수로 여러가지 값 표현 [수시]

#include "stdafx.h"
#include <stdio.h>

#define OPTION1_MAN 0x00000000
#define OPTION1_WOMAN 0x00000001

#define OPTION2_SEOUL 0x00000010
#define OPTION2_BUSAN 0x00000020
#define OPTION2_DAEGU 0x00000030

#define OPTION3_CAR 0x00000100
#define OPTION3_TRAIN 0x00000200
#define OPTION3_PLAIN 0x00000300


int main(int argc, char* argv[])
{
 int a = OPTION1_MAN | OPTION2_BUSAN | OPTION3_PLAIN;

 printf("%x\n",a);

 int op1, op2, op3;
 
 op1 = 0x0000000F & a;

 op2 = 0x000000F0 & a;

 op3 = 0x00000F00 & a;

 printf("%x %x %x\n",op3, op2, op1);



 return 0;
}