Download presentation
Presentation is loading. Please wait.
Published byHope Blankenship Modified over 6 years ago
1
En eventueel een subtitel om de nieuwsgierigheid aan te wakkeren
Javascript BITWISE En eventueel een subtitel om de nieuwsgierigheid aan te wakkeren 1 juni 2016
2
BITWISE GAAT OVER BINAIRE BEWERKINGEN
Javascript BITWISE 1 juni 2016
3
00110100 = 4 + 16 + 32 = 52 Decimaal naar binair:
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE GAAT OVER BINAIRE BEWERKINGEN = = 52 Decimaal naar binair: 3 = > > 11 = > > Javascript BITWISE 1 juni 2016
4
Intermediate DOM[edit]
In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “OF” bewerking | Rekenregel: OF 1 OR 1 = 1 1 OR 0 = 1 0 OR 1 = 1 0 OR 0 = 0 3 = 11 = Onder elkaar = (tabel) = (dec) 11 Javascript BITWISE 1 juni 2016
5
BITWISE “OF” bewerking |
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “OF” bewerking | Javascript BITWISE 1 juni 2016
6
3 = 0011 11 = 1011 Onder elkaar 0011 = (tabel) 0 + 0 + 2 + 1 = (dec) 3
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “AND” bewerking | Rekenregel: AND 1 AND 1 = 1 1 AND 0 = 0 0 AND 1 = 0 0 AND 0 = 0 3 = 11 = Onder elkaar = (tabel) = (dec) 3 Javascript BITWISE 1 juni 2016
7
BITWISE “AND” bewerking |
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “AND” bewerking | Javascript BITWISE 1 juni 2016
8
(dec) ~7 = ~0111 = 1000 = (dec) 8 (dec) ~3 = ~11 = 00 = (dec) 0
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “NOT” bewerking | (dec) ~7 = ~0111 = 1000 = (dec) 8 (dec) ~3 = ~11 = 00 = (dec) 0 Javascript BITWISE 1 juni 2016
9
ALLEEN ALS één van beide “1” is dan is het resultaat “1”
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “XOR” bewerking Exclusief OR ^ ALLEEN ALS één van beide “1” is dan is het resultaat “1” 10^2 = 0010 XOR 1010 = 1000 (dec 8) Javascript BITWISE 1 juni 2016
10
<< Left shift x = 5 << 1 0101 << 1 1010 10
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “<<” en “>>” SHIFT << Left shift x = 5 << << Javascript BITWISE 1 juni 2016
11
>>Right shift x = 5 >> 1 0101 >> 1 0010 2
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “<<” en “>>” SHIFT >>Right shift x = 5 >> >> 2 Javascript BITWISE 1 juni 2016
12
BITWISE “NOT” bewerking ~ (signed bit
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE “NOT” bewerking ~ (signed bit Javascript BITWISE 1 juni 2016
13
BITWISE – script Intermediate DOM[edit]
In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE – script Javascript BITWISE 1 juni 2016
14
BITWISE – floating functies
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE – floating functies Javascript BITWISE 1 juni 2016
15
BITWISE – floating functies
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE – floating functies IEEE 754 is een standaard van de IEEE die een manier beschrijft om getallen met zwevende komma voor te stellen in het geheugen van een binaire rekenmachine (computer). Een belangrijke doelstelling van de standaard is, berekeningen waarin dergelijke getallen voorkomen snel te laten verlopen. Deze standaard moet ondersteund worden door het computersysteem, en niet zozeer door de hardware zelf. De meeste architecturen ondersteunen de IEEE 754-standaard. Er zijn er enkele (oudere) die de standaard niet ondersteunen zoals IBM System/370 en de DEC VAX. Javascript BITWISE 1 juni 2016
16
BITWISE – floating functies
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE – floating functies Javascript BITWISE 1 juni 2016
17
BITWISE – floating functies
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." BITWISE – floating functies Javascript BITWISE 1 juni 2016
18
BITWISE – floating functies
Javascript BITWISE 1 juni 2016
19
BITWISE – functies Javascript BITWISE 1 juni 2016
20
var result = number.toString(2);
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." Most of us know know that there are some bitwise operators in JS. Every number has it's own binary representation, used by those operators. To check dec number's binary value, we use .toString() method with base argument - '2' for binary: var number = 3; var result = number.toString(2); // In case we want to change the number directly, not // a variable with a number value, we need to use two // dots - it's equivalent of 14.0.toString where we can // show that decimal part of the number is equal to 0. var result2 = 14..toString(2); document.getElementById('result').innerHTML = result + ', ' + result2; Javascript BITWISE 1 juni 2016
21
// helper function for displaing results
var output = function(operator, result) { document.getElementById(operator).innerHTML = result; } // variables var a = 5; var b = 13; // a | b - OR // if in any of the given numbers corresponding bit // is '1', then the result is '1' output('or', a|b); // 13 // a & b - AND // if in both of the given numbers corresponding bit output('and', a&b); // 5 // a ^ b - XOR // if in one of the given numbers (not both) // corresponding bit is '1', then the result is '1' output('xor', a^b); // 8 // ~a - NOT // inverts all the bits output('not', ~a); // -6 // a >> b - RIGHT SHIFT // shift binary representation of 'a' for 'b' // bits to the right, discarding bits shifted off output('rs', a>>b); // 0 // a << b - LEFT SHIFT // bits to the right, shifting in zeros from the right output('ls', a<<b); // 40960 // a >>> b - ZERO FILLED RIGHT SHIFT // bits to the right, discarding bits shifted off, // and shifting in zeros from the left. output('zfrs', a>>>b); // 0 Javascript BITWISE 1 juni 2016
22
document.getElementById('result').innerHTML = result;
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." Sometime we even use Bitwise OR as equivalent of Math.floor(): var data = ; var result = data | 0; document.getElementById('result').innerHTML = result; It has the same effect as double NOT operator (my favorite rounding solution since I first heard about it on Damian Wielgosik's workshop couple of years ago). var data = ; var result = ~~data; document.getElementById('result').innerHTML = result; Javascript BITWISE 1 juni 2016
23
/ helper function for displaying results
What about other real life examples of bit chaking? For instance, we can convert colors from RGA to Hex format / helper function for displaying results var output = function(operator, result) { document.getElementById(operator).innerHTML = result; } // variables var color = {r: 186, g: 218, b: 85}; // RGB to HEX var rgb2hex = function(r, g, b) { return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).substr(1); output('color', rgb2hex(color.r, color.g, color.b)); Javascript BITWISE 1 juni 2016
24
// helper function for displaying results
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." // helper function for displaying results var output = function(operator, result) { document.getElementById(operator).innerHTML = result; } // variables var a = 9285; var b = 3569; // a ^ ((a ^ b) & -(a < b)) - which one, a or b, is bigger? output('max', a ^ ((a ^ b) & -(a < b))); // b ^ ((a ^ b) & -(a < b)) - which one, a or b, is smaller? output('min', b ^ ((a ^ b) & -(a < b))); Javascript BITWISE 1 juni 2016
25
// helper function for displaying results
Intermediate DOM[edit] In 1997, Netscape and Microsoft released version 4.0 of Netscape Navigator and Internet Explorer respectively, adding support for Dynamic HTML (DHTML), functionality enabling changes to a loaded HTML document. DHTML required extensions to the rudimentary document object that was available in the Legacy DOM implementations. Although the Legacy DOM implementations were largely compatible since JScript was based on JavaScript, the DHTML DOM extensions were developed in parallel by each browser maker and remained incompatible. These versions of the DOM became known as the "Intermediate DOM." // helper function for displaying results var output = function(operator, result) { document.getElementById(operator).innerHTML = result; } // variables var a = 10; var b = 99; // a^=b, b^=a, a^=b - swap variables using XOR operation, // details: a^=b, b^=a, a^=b; output('a', a); output('b', b); Javascript BITWISE 1 juni 2016
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.