ﺪﻨﮐ ﯽﻣ ﻢﯿﻈﻨﺗ 1 ﯼﻭﺭ ﺍﺭ ﺖﯿﺑ ﺮﻫ ،ﺪﻨﺷﺎﺑ 1 ﺖﯿﺑ ﻭﺩ ﺮﻫ ﺮﮔﺍ .ﻭ ﻖﻄﻨﻣ
ﺪﻨﮐ ﯽﻣ ﻢﯿﻈﻨﺗ 1 ﯼﻭﺭ ﺍﺭ ﺖﯿﺑ ﺮﻫ ،ﺪﺷﺎﺑ 1 ﺖﯿﺑ ﻭﺩ ﺯﺍ ﯽﮑﯾ ﺮﮔﺍ .ﺎﯾ ﻖﻄﻨﻣ
ﺪﻨﮐ ﯽﻣ ﻢﯿﻈﻨﺗ 1 ﯼﻭﺭ ﺍﺭ ﺖﯿﺑ ﺮﻫ ،ﺪﺷﺎﺑ 1 ﺖﯿﺑ ﻭﺩ ﺯﺍ ﯽﮑﯾ ﻂﻘﻓ ﺮﮔﺍ .XOR ﻖﻄﻨﻣ
ﺪﻨﮐ ﯽﻣ ﺱﻮﮑﻌﻣ ﺍﺭ ﺎﻫ ﺖﯿﺑ ﻪﻤﻫ .ﻪﻧ ﻖﻄﻨﻣ
ﺪﻨﺘﻔﯿﺑ ﻦﯿﯾﺎﭘ ﭗﭼ ﯼﺎﻫﺖﻤﺴﻗ ﻪﮐ ﺪﻫﺩﯽﻣ ﻩﺯﺎﺟﺍ ﻭ ﺩﻮﺷﯽﻣ ﺎﺟﻪﺑﺎﺟ ﭗﭼ ﺖﻤﺳ ﻪﺑ ﺖ
ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ ﺎﻫ ﺖﯿﺑ ﻦﯾﺮﺗ ﺖﺳﺍﺭ ﺖﻤﺳ ﻪﺑ ﻭ ﺩﻮﺷ ﯽﻣ ﺎﺟ ﻪﺑﺎﺟ ﺖﺳﺍﺭ ﺖﻤﺳ ﻪﺑ ﭗﭼ ﺖﻤﺳ ﺯﺍ ﺖﯿﺑ ﻦﯾﺮﺗ
ﺪﻨﺘﻔﯿﺑ ﺎﻫﺖﯿﺑ ﻦﯾﺮﺗﺖﺳﺍﺭ ﺖﻤﺳ ﺪﻫﺩﯽﻣ ﻩﺯﺎﺟﺍ ﻭ ﺩﻮﺷﯽﻣ ﺎﺟﻪﺑﺎﺟ ﺖﺳﺍﺭ ﺖﻤ
Operation | Result | Same as | Result |
---|---|---|---|
5 & 1 | 1 | 0101 & 0001 | 0001 |
5 | 1 | 5 | 0101 | 0001 | 0101 |
~ 5 | 10 | ~0101 | 1010 |
5 << 1 | 10 | 0101 << 1 | 1010 |
5 ^ 1 | 4 | 0101 ^ 0001 | 0100 |
5 >> 1 | 2 | 0101 >> 1 | 0010 |
5 >>> 1 | 2 | 0101 >>> 1 | 0010 |
ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﺘﯿﺑ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺎﻬﻧﺁ ﻪﻤﻫ ﺎﻣﺍ ،ﺪﻨﮐ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﺘﯿﺑ 64 ﺭﻭﺎﻨﺷ ﺰﯿﻤﻣ ﺩﺍﺪﻋﺍ ﺕﺭﻮﺻ
ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﺖﯿﺑ 32 ﻪﺑ ﺍﺭ ﺩﺍﺪﻋﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﯽﺘﯿﺑ ﺕﺎﯿﻠﻤﻋ ﻡﺎﺠﻧﺍ ﺯﺍ ﻞﺒﻗ
ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﯽﺘﯿﺑ 64 ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﻪﺠﯿﺘﻧ ،ﯽﺘﯿﺑ ﺕﺎﯿﻠﻤﻋ ﻡﺎﺠﻧﺍ ﺯﺍ ﺲﭘ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 10 ﺩﺪﻋ 5 ~ ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ .ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺘﯿﺑ 4 ﺖﻣﻼﻋ ﻥﻭﺪﺑ ﯼﺮﻨﯾﺎﺑ ﺩﺍﺪﻋ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ -6 .ﺪﻧﺍﺩﺮﮔ ﯽﻤﻧ ﺮﺑ ﺍﺭ 10 ،ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺘﯿﺑ 32 ﻩﺪﺷ ﺎﻀﻣﺍ ﺢﯿﺤﺻ ﺩﺍﺪﻋﺍ ﺯ
0000000000000000000000000000101 (5)
11111111111111111111111111111010 (~5=-6)
.ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﻔﻨﻣ ﺖﻣﻼﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﭗﭼ ﺖﻤﺳ ﺖﯿﺑ ﺯﺍ ﻩﺪﺷ ﺎﻀﻣﺍ ﺢﯿﺤﺻ ﺩﺪﻋ ﮏﯾ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 1 ،ﺪﻨﺷﺎﺑ 1 ﺖﯿﺑ ﻭﺩ ﺮﻫ ﺮﮔﺍ ،ﺩﻮﺷ ﯽﻣ ﻡﺎﺠﻧﺍ ﺖﯿﺑ ﺖﻔﺟ ﮏﯾ ﯼﻭﺭ AND ﺖﯿﺑ ﮏﯾ ﻪﮐ ﯽ
0
0
0
1
0000
0001
0010
0100
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 1 ،ﺪﺷﺎﺑ 1 ﺎﻫ ﺖﯿﺑ ﺯﺍ ﯽﮑﯾ ﺮﮔﺍ ،ﺩﻮﺷ ﯽﻣ ﻡﺎﺠﻧﺍ ﺖﯿﺑ ﺖﻔﺟ ﮏﯾ ﯼﻭﺭ ﯽﺘﯿﺑ OR ﮏﯾ ﻪ
0
1
1
1
1111
1111
1111
1111
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 1 ،ﺪﻨﺷﺎﺑ ﺕﻭﺎﻔﺘﻣ ﺎﻫ ﺖﯿﺑ ﺮﮔﺍ ،ﺩﻮﺷ ﯽﻣ ﻡﺎﺠﻧﺍ ﺖﯿﺑ ﺖﻔﺟ ﮏﯾ ﯼﻭﺭ ﯽﺘﯿﺑ XOR ﮏﯾ ﻪ
0
1
1
0
1111
1110
1101
1011
Bitwise AND ﺪﻨﺷﺎﺑ 1 ﺖﯿﺑ ﻭﺩ ﺮﻫ ﻪﮐ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 1 ﯽﺗﺭﻮﺻ ﺭﺩ ﺎﻬﻨﺗ:
00000000000000000000000000000101
00000000000000000000000000000001
00000000000000000000000000000001 (1)
let x = 5 & 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Bitwise AND</h1>
<h2>The & Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 & 1;
</script>
</body>
</html>
Bitwise OR 1 ﺪﺷﺎﺑ 1 ﺎﻫ ﺖﯿﺑ ﺯﺍ ﯽﮑﯾ ﺮﮔﺍ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ:
00000000000000000000000000000101
00000000000000000000000000000001
0000000000000000000000000000101 (5)
let x = 5 | 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Bitwise OR</h1>
<h2>The | Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 | 1;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ 1 ﯽﺘﯿﺑ XOR ،ﺪﻨﺷﺎﺑ ﺕﻭﺎﻔﺘﻣ ﺎﻫ ﺖﯿﺑ ﺮﮔﺍ
00000000000000000000000000000101
00000000000000000000000000000001
0000000000000000000000000000100 (4)
let x = 5 ^ 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Bitwise XOR</h1>
<h2>The ^ Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 ^ 1;
</script>
</body>
</html>
00000000000000000000000000000101
11111111111111111111111111111010 (-6)
let x = ~5;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Bitwise NOT</h1>
<h2>The ~ Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = ~ 5;
</script>
</body>
</html>
،ﺩﻮﺷ ﯽﻣ ﻩﺩﺍﺩ ﺭﺎﺸﻓ ﻞﺧﺍﺩ ﻪﺑ ﺖﺳﺍﺭ ﺖﻤﺳ ﺯﺍ ﺮﻔﺻ ﺖﯿﺑ ﺪﻨﭼ ﺎﯾ ﮏﯾ .ﺖﺳﺍ ﺮﻔﺻ ﺮﭘ ﭗﭼ ﺖﻔﯿﺷ ﮏﯾ ﻦﯾﺍ
00000000000000000000000000000101
0000000000000000000000000001010 (10)
let x = 5 << 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Bitwise Left</h1>
<h2>The << Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 << 1;
</script>
</body>
</html>
ﺪﻧﻮﺷ ﯽﻣ ﻩﺩﺍﺩ ﺭﺎﺸﻓ ﺖﯿﺑ ﻦﯾﺮﺗ ﭗﭼ ﺖﻤﺳ ﯼﺎﻫ ﯽﭙﮐ .ﺪﻨﮐ ﯽﻣ ﻆﻔﺣ ﺍﺭ ﺖﺳﺍﺭ ﺖﻤﺳ ﺮﯿﯿﻐﺗ ﻪﮐ ﺖﺳﺍ ﯼﺍ ﻪﻧﺎ
11111111111111111111111111111011
11111111111111111111111111111101 (-3)
let x = -5 >> 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Signed Bitwise Right</h1>
<h2>The >> Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = -5 >> 1;
</script>
</body>
</html>
،ﺩﻮﺷ ﯽﻣ ﻩﺩﺍﺩ ﻞﻫ ﻞﺧﺍﺩ ﻪﺑ ﭗﭼ ﺖﻤﺳ ﺯﺍ ﺮﻔﺻ ﺖﯿﺑ ﺪﻨﭼ ﺎﯾ ﮏﯾ .ﺖﺳﺍ ﺮﻔﺻ ﻥﺩﺮﮐ ﺮﭘ ﺖﺳﺍﺭ ﺖﻤﺳ ﻪﺑ ﺖﻔﯿﺷ
00000000000000000000000000000101
00000000000000000000000000000010 (2)
let x = 5 >>> 1;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Unsigned Bitwise Right</h1>
<h2>The >>> Operator</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 >>> 1;
</script>
</body>
</html>
:ﺪﻨﺘﺴﻫ ﮎﺭﺩ ﻞﺑﺎﻗ ﯽﺘﺣﺍﺭ ﻪﺑ ﺖﯿﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺎﻬﻨﺗ ﺎﺑ ﯼﺮﻨﯾﺎﺑ ﺩﺍﺪﻋﺍ
1
2
4
8
16
32
64
:ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﯼﺮﻨﯾﺎﺑ ﯼﻮﮕﻟﺍ ﺮﮕﯾﺩ ﺖﯿﺑ ﺪﻨﭼ ﻢﯿﻈﻨﺗ
5 (4 + 1)
13 (8 + 4 + 1)
45 (32 + 8 + 4 + 1)
.ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﻭﺩ ﻞﻤﮑﻣ ﺐﻟﺎﻗ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺮﻨﯾﺎﺑ ﺩﺍﺪﻋﺍ
:ﺖﺳﺍ 1 ﻪﻓﺎﺿﺍ ﻪﺑ ﺩﺪﻋ NOT ﯽﺘﯿﺑ ﺕﺭﻮﺻ ﻪﺑ ﯽﻔﻨﻣ ﺩﺪﻋ ﮏﯾ ﻪﮐ ﺖﺳﺍ ﯽﻨﻌﻣ ﻥﺍﺪﺑ ﻦﯾﺍ
5
-5
6
-6
40
-40
.ﺪﻨﻧﺍﺩ ﯽﻤﻧ ﻪﮐ ﯽﯾﺎﻬﻧﺁ ﻭ ﺪﻨﻤﻬﻓ ﯽﻣ ﺍﺭ ﯼﺮﻨﯾﺎﺑ ﻪﮐ ﯽﯾﺎﻬﻧﺁ :ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺎﯿﻧﺩ ﺭﺩ ﻡﺩﺁ ﻉﻮﻧ 10 ﻂﻘﻓ
function dec2bin(dec){
return (dec >>> 0).toString(2);
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Convert Decimal to Binary</h1>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = dec2bin(-5);
function dec2bin(dec){
return (dec >>> 0).toString(2);
}
</script>
</body>
</html>
function bin2dec(bin){
return parseInt(bin, 2).toString(10);
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Convert Binary to Decimal</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = bin2dec(101);
function bin2dec(bin){
return parseInt(bin, 2).toString(10);
}
</script>
</body>
</html>