Creative Code

letterAttribute2.c (BOLD,ITALIC,SHADOW,UL) 본문

카테고리 없음

letterAttribute2.c (BOLD,ITALIC,SHADOW,UL)

빛하루 2023. 8. 1. 16:41
#include <stdio.h>
#define BOLD (0x01<<0)    //0x01<<0
#define ITALIC (0x01 << 1)  // 0x01 << 1
#define SHADOW (0x01 << 2)   // 0x01 << 2
#define UL (0x01<<3)      // 0x01 <<3,  시프트연산을 전처리해주려면 괄호를 써야한다 (안쓸 시 밑에 shadow+ italic에서 연산자 우선순위에 의해 계산이 꼬일 수 있음

int main(void)
{
	unsigned char attr;
	attr = attr ^ attr;               // attr = 0; 결과는 attr = 0x00
	attr = attr | BOLD;           // 00000001 결과는 attr = 0x01
	attr = attr | (SHADOW + ITALIC);// 00000110 결과는 attr = 0x07
	attr = attr & ~BOLD;              // 비트 맨끝에 있는 숫자를 바꾼다(00000111 -> 00000110)
	
	printf("attr : ");
	if (attr & BOLD){ // c언어에서는 괄호안의 값이 nonzero면 참이라고 생각한다.
		printf("BOLD");
	}
	if (attr & ITALIC){
		printf("ITALIC ");
	}
	if (attr & SHADOW){
		printf("SHADOW ");
	}
	if (attr & UL){
		printf("UL ");
	}
	printf("\n");
	return 0;
}