C빈칸 채우기보통 · 20점#비트 연산#진법 변환#반복문

57. 비트 켜기·끄기와 2진수 출력

다음 C 프로그램의 실행 결과가 차례로 `10110`, `10011`, `11011`, `27 odd`가 되도록 빈칸 ①, ②에 들어갈 연산자를 쓰시오. (①은 시프트 연산자, ②는 단항 비트 연산자다)

1#include <stdio.h>
2
3void printBin(int v) {
4 for (int i = 4; i >= 0; i--) {
5 printf("%d", (v ( ① ) i) & 1);
6 }
7 printf("\n");
8}
9
10int main() {
11 int v = 22;
12 printBin(v);
13 v |= 1 << 0;
14 v &= ( ② )(1 << 2);
15 printBin(v);
16 v ^= 1 << 3;
17 printBin(v);
18 printf("%d %s\n", v, (v & 1) ? "odd" : "even");
19 return 0;
20}

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.