-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex06-13.html
40 lines (40 loc) · 1.41 KB
/
ex06-13.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>비트 연산</title>
<script>
function digit8(v) {
let str="";
for(let i=0; i<8; i++, v<<=1) {
if((v & 0x80)) str += "1";
else str += "0";
}
return str;
}
</script>
</head>
<body>
<h3>비트 논리 연산과 시프트 연산</h3>
<hr>
<script>
let x=10, y=3;
document.write("<pre>");
document.write("x=" + x + ", y=" + y + "<br>");
document.write("x : " + digit8(x) + "<br>");
document.write("y : " + digit8(y) + "<br>");
document.write("<hr>");
document.write("x & y: " + digit8(x&y) + "<br>");
document.write("x | y: " + digit8(x|y) + "<br>");
document.write("x ^ y: " + digit8(x^y) + "<br>");
document.write("~x: " + digit8(~x) + "<br>");
document.write("<hr>");
document.write("x << 1: " + digit8(x<<1) + " (" + (x<<1) + ")<br>");
document.write("x >> 1: " + digit8(x>>1) + " (" + (x>>1) + ")<br>");
document.write("x >>> 1: " + digit8(x>>>1) + " (" + (x>>>1) + ")");
document.write("</pre>");
</script>
</body>
</html>