Skip to content

Commit eec77e3

Browse files
authored
Merge pull request #306 from per1234/unix-eol
Use Unix EOL in all files
2 parents 8545002 + 7547a2b commit eec77e3

37 files changed

+2537
-2467
lines changed
Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,120 @@
1-
---
2-
title: "<<"
3-
title_expanded: 비트 왼쪽으로 옮김
4-
categories: [ "Structure" ]
5-
subCategories: [ "비트 연산자" ]
6-
---
7-
8-
9-
10-
11-
12-
= << 비트 왼쪽으로 옮김
13-
14-
15-
// OVERVIEW SECTION STARTS
16-
[#overview]
17-
--
18-
19-
[float]
20-
=== 설명
21-
비트 왼쪽으로 옮김 연산자 `<<` 는 왼쪽 피연산자의 비트를 오른쪽 피연산자가 지정한 위치 수 만큼 왼쪽으로 옮긴다.
22-
23-
[%hardbreaks]
24-
25-
26-
[float]
27-
=== 문법
28-
[source,arduino]
29-
----
30-
변수 << 비트 수;
31-
----
32-
33-
[float]
34-
=== 매개변수
35-
`변수`: *허용되는 자료형:* byte, int, long +
36-
`비트 수`: 숫자 < = 32. *허용되는 자료형:* int
37-
38-
--
39-
// OVERVIEW SECTION ENDS
40-
41-
42-
43-
// HOW TO USE SECTION STARTS
44-
[#howtouse]
45-
--
46-
47-
[float]
48-
=== 예제 코드
49-
50-
[source,arduino]
51-
----
52-
int a = 5; // 이진수: 0000000000000101
53-
int b = a << 3; // 이진수: 0000000000101000, 즉 십진수 40
54-
----
55-
[%hardbreaks]
56-
57-
[float]
58-
=== 주의와 경고
59-
값 x를 y 비트 옮기면(x << y), 가장 왼쪽에 있는 y 비트를 잃어 문자 그대로 존재하지 않게 됨:
60-
[source,arduino]
61-
----
62-
int x = 5; // 이진수: 0000000000000101
63-
int y = 14;
64-
int result = x << y; // 이진수: 0100000000000000 - 101에서 처음의 1은 버려짐
65-
----
66-
값의 어떤 것도 망각으로 옮겨지지 않는다고 확신한다면, 왼쪽 쉬프트 연산자를 생각하는 간단한 방법은 왼쪽 피연산자에 2의 오른쪽 피연산자 제곱을 곱하는 것이다. 예를 들어 2의 거듭제곱을 생성하려면 다음 표현식을 사용할 수 있다:
67-
68-
[source,arduino]
69-
----
70-
  연산       결과
71-
--------- ------
72-
1 << 0 1
73-
1 << 1 2
74-
1 << 2 4
75-
1 << 3 8
76-
...
77-
1 << 8 256
78-
1 << 9 512
79-
1 << 10 1024
80-
...
81-
----
82-
83-
다음 예제는 왼쪽으로 옮김 연산자를 사용하여 바이트를 바닥(LSB)에서 꼭대기(MSB)로 옮기고 이진 값을 출력하여, 받은 바이트 값을 시리얼 모니터에 출력하는 데 사용할 수 있다:
84-
[source,arduino]
85-
----
86-
// 이진값 (1 or 0) 출력
87-
void printOut1(int c) {
88-
for (int bits = 7; bits > -1; bits--) {
89-
// Compare bits 7-0 in byte
90-
if (c & (1 << bits)) {
91-
Serial.print("1");
92-
}
93-
else {
94-
Serial.print("0");
95-
}
96-
}
97-
}
98-
----
99-
[%hardbreaks]
100-
101-
--
102-
// HOW TO USE SECTION ENDS
103-
104-
105-
106-
107-
//SEE ALSO SECTION STARTS
108-
[#see_also]
109-
--
110-
111-
[float]
112-
=== 더보기
113-
114-
[role="language"]
115-
116-
[role="example"]
117-
* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^]
118-
119-
--
120-
//SEE ALSO SECTION ENDS
1+
---
2+
title: "<<"
3+
title_expanded: 비트 왼쪽으로 옮김
4+
categories: [ "Structure" ]
5+
subCategories: [ "비트 연산자" ]
6+
---
7+
8+
9+
10+
11+
12+
= << 비트 왼쪽으로 옮김
13+
14+
15+
// OVERVIEW SECTION STARTS
16+
[#overview]
17+
--
18+
19+
[float]
20+
=== 설명
21+
비트 왼쪽으로 옮김 연산자 `<<` 는 왼쪽 피연산자의 비트를 오른쪽 피연산자가 지정한 위치 수 만큼 왼쪽으로 옮긴다.
22+
23+
[%hardbreaks]
24+
25+
26+
[float]
27+
=== 문법
28+
[source,arduino]
29+
----
30+
변수 << 비트 수;
31+
----
32+
33+
[float]
34+
=== 매개변수
35+
`변수`: *허용되는 자료형:* byte, int, long +
36+
`비트 수`: 숫자 < = 32. *허용되는 자료형:* int
37+
38+
--
39+
// OVERVIEW SECTION ENDS
40+
41+
42+
43+
// HOW TO USE SECTION STARTS
44+
[#howtouse]
45+
--
46+
47+
[float]
48+
=== 예제 코드
49+
50+
[source,arduino]
51+
----
52+
int a = 5; // 이진수: 0000000000000101
53+
int b = a << 3; // 이진수: 0000000000101000, 즉 십진수 40
54+
----
55+
[%hardbreaks]
56+
57+
[float]
58+
=== 주의와 경고
59+
값 x를 y 비트 옮기면(x << y), 가장 왼쪽에 있는 y 비트를 잃어 문자 그대로 존재하지 않게 됨:
60+
[source,arduino]
61+
----
62+
int x = 5; // 이진수: 0000000000000101
63+
int y = 14;
64+
int result = x << y; // 이진수: 0100000000000000 - 101에서 처음의 1은 버려짐
65+
----
66+
값의 어떤 것도 망각으로 옮겨지지 않는다고 확신한다면, 왼쪽 쉬프트 연산자를 생각하는 간단한 방법은 왼쪽 피연산자에 2의 오른쪽 피연산자 제곱을 곱하는 것이다. 예를 들어 2의 거듭제곱을 생성하려면 다음 표현식을 사용할 수 있다:
67+
68+
[source,arduino]
69+
----
70+
  연산       결과
71+
--------- ------
72+
1 << 0 1
73+
1 << 1 2
74+
1 << 2 4
75+
1 << 3 8
76+
...
77+
1 << 8 256
78+
1 << 9 512
79+
1 << 10 1024
80+
...
81+
----
82+
83+
다음 예제는 왼쪽으로 옮김 연산자를 사용하여 바이트를 바닥(LSB)에서 꼭대기(MSB)로 옮기고 이진 값을 출력하여, 받은 바이트 값을 시리얼 모니터에 출력하는 데 사용할 수 있다:
84+
[source,arduino]
85+
----
86+
// 이진값 (1 or 0) 출력
87+
void printOut1(int c) {
88+
for (int bits = 7; bits > -1; bits--) {
89+
// Compare bits 7-0 in byte
90+
if (c & (1 << bits)) {
91+
Serial.print("1");
92+
}
93+
else {
94+
Serial.print("0");
95+
}
96+
}
97+
}
98+
----
99+
[%hardbreaks]
100+
101+
--
102+
// HOW TO USE SECTION ENDS
103+
104+
105+
106+
107+
//SEE ALSO SECTION STARTS
108+
[#see_also]
109+
--
110+
111+
[float]
112+
=== 더보기
113+
114+
[role="language"]
115+
116+
[role="example"]
117+
* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^]
118+
119+
--
120+
//SEE ALSO SECTION ENDS

0 commit comments

Comments
 (0)