bitwise-operation
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,2 +0,2 @@ | ||
// Bitwise.js 1.1.0 | ||
// Bitwise.js 1.1.1 | ||
// Bitwise may be freely distributed under the MIT license. | ||
@@ -8,3 +8,3 @@ (function(){/** | ||
*/ | ||
function t(e){var n=this;if(!(n instanceof t))return new t(e);if(Array.isArray(e))n.value=0,e.forEach(function(t,e){n.value|=(t?1:0)<<e});else if("string"==typeof e){var r=0;n.value=0;for(var o=e.length-1;o>=0;o--)("1"===e[o]||"0"===e[o])&&(n.value|=("1"===e[o]?1:0)<<r,r++)}else n.value=e||0}t.VERSION="1.1.0",t.not=function(t){return~t},t.and=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.and(e.shift());return n.valueOf()},t.nand=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.nand(e.shift());return n.valueOf()},t.andNot=t.nand,t.or=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.or(e.shift());return n.valueOf()},t.nor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.nor(e.shift());return n.valueOf()},t.xor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.xor(e.shift());return n.valueOf()},t.xnor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.xnor(e.shift());return n.valueOf()},t.nxor=t.xnor,t.toggle=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.toggle(e.shift());return n.valueOf()},t.swap=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.swap(e.shift());return n.valueOf()},t.mask=function(e,n){var r=Array.prototype.slice.call(arguments);return n=r.pop(),e=r.pop()||0,t(0).setRange(e,n).valueOf()},t.prototype.valueOf=function(){return this.value},t.prototype.copy=function(){return new t(this.value)},t.prototype.clone=t.prototype.copy,t.prototype.toString=function(t,e){var n=Array.prototype.slice.call(arguments),r=this.value.toString(2);return n.length<2?r:r.replace(new RegExp("\\B(?=(\\d{"+t+"})+(?!\\d))","g"),e)},t.prototype.toArray=function(){var t=this.value,e=[];if(0===t)return[0];for(;t>0;)e.push(t&1>0?1:0),t>>=1;return e},t.prototype.cardinality=function(){return this.toString().match(/(1)/g).length},t.prototype.length=function(){return this.value>=0&&Number.isSafeInteger(this.value)?this.toString().length:Number.MAX_SAFE_INTEGER.toString(2).length},t.prototype.size=t.prototype.length,t.prototype.not=function(){return this.value=~this.value,this},t.prototype.and=function(e){return e instanceof t&&(e=e.valueOf()),this.value&=e,this},t.prototype.nand=function(t){return this.and(t).not(),this},t.prototype.andNot=t.prototype.nand,t.prototype.or=function(e){return e instanceof t&&(e=e.valueOf()),this.value|=e,this},t.prototype.nor=function(t){return this.or(t).not(),this},t.prototype.xor=function(t){return this.value=this.copy().or(t).and(this.copy().and(t).not()).valueOf(),this},t.prototype.xnor=function(t){return this.xor(t).not(),this},t.prototype.nxor=t.prototype.xnor,t.prototype.set=function(t,e){return e===!1?this.unset(t):0>t?this:(this.value|=1<<t,this)},t.prototype.unset=function(t){return 0>t?this:(this.value&=~(1<<t),this)},t.prototype.get=function(t){return 0>t?!1:(this.value&1<<t)>0},t.prototype.toggle=function(t){return this.set(t,!this.get(t)),this},t.prototype.swap=function(t,e){if(0>t||0>e)return this;Array.isArray(t)&&(e=t.pop(),t=t.shift());var n=this.copy();return this.set(e,n.get(t)),this.set(t,n.get(e)),this},t.prototype.equals=function(e){return e instanceof t&&(e=e.valueOf()),this.value===e},t.prototype.setValue=function(e){return e instanceof t&&(e=e.valueOf()),this.value=e,this},t.prototype.setRange=function(e,n){return 0>e||0>n?this:(this.value|=t.xor((1<<e)-1,(1<<n<<1)-1),this)},t.prototype.unsetRange=function(e,n){return 0>e||0>n?this:(this.value&=~t.xor((1<<e)-1,(1<<n<<1)-1),this)},t.prototype.toggleRange=function(e,n){if(0>e||0>n)return this;var r=t.mask(e,n);return this.value=this.copy().not().and(r).or(this.copy().and(t.not(r))).valueOf(),this},t.prototype.mask=function(e,n){return this.and(t.mask(e,n)),this},t.prototype.clear=function(e,n){return this.and(t.not(t.mask(e,n))),this};var e=this;"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=t),exports.Bitwise=t):e.Bitwise=t,"function"==typeof define&&define.amd&&define("bitwise",[],function(){return t})}).call(this); | ||
function t(e){var n=this;if(!(n instanceof t))return new t(e);if(Array.isArray(e))n.value=0,e.forEach(function(t,e){n.value|=(t?1:0)<<e});else if("string"==typeof e){var r=0;n.value=0;for(var o=e.length-1;o>=0;o--)("1"===e[o]||"0"===e[o])&&(n.value|=("1"===e[o]?1:0)<<r,r++)}else n.value=e||0}t.VERSION="1.1.1",t.not=function(t){return~t},t.and=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.and(e.shift());return n.valueOf()},t.nand=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.nand(e.shift());return n.valueOf()},t.andNot=t.nand,t.or=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.or(e.shift());return n.valueOf()},t.nor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.nor(e.shift());return n.valueOf()},t.xor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.xor(e.shift());return n.valueOf()},t.xnor=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.xnor(e.shift());return n.valueOf()},t.nxor=t.xnor,t.toggle=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.toggle(e.shift());return n.valueOf()},t.swap=function(){var e=Array.prototype.slice.call(arguments),n=e.shift();for(n instanceof t||(n=new t(n));e.length>0;)n.swap(e.shift());return n.valueOf()},t.mask=function(e,n){var r=Array.prototype.slice.call(arguments);return n=r.pop(),e=r.pop()||0,t(0).setRange(e,n).valueOf()},t.prototype.valueOf=function(){return this.value},t.prototype.copy=function(){return new t(this.value)},t.prototype.clone=t.prototype.copy,t.prototype.toString=function(t,e){var n=Array.prototype.slice.call(arguments),r=this.value.toString(2);return n.length<2?r:r.replace(new RegExp("\\B(?=(\\d{"+t+"})+(?!\\d))","g"),e)},t.prototype.toArray=function(){var t=this.value,e=[];if(0===t)return[0];for(;t>0;)e.push(t&1>0?1:0),t>>=1;return e},t.prototype.cardinality=function(){return this.toString().match(/(1)/g).length},t.prototype.length=function(){return this.value>=0&&Number.isSafeInteger(this.value)?this.toString().length:Number.MAX_SAFE_INTEGER.toString(2).length},t.prototype.size=t.prototype.length,t.prototype.not=function(){return this.value=~this.value,this},t.prototype.and=function(e){return e instanceof t&&(e=e.valueOf()),this.value&=e,this},t.prototype.nand=function(t){return this.and(t).not(),this},t.prototype.andNot=t.prototype.nand,t.prototype.or=function(e){return e instanceof t&&(e=e.valueOf()),this.value|=e,this},t.prototype.nor=function(t){return this.or(t).not(),this},t.prototype.xor=function(t){return this.value=this.copy().or(t).and(this.copy().and(t).not()).valueOf(),this},t.prototype.xnor=function(t){return this.xor(t).not(),this},t.prototype.nxor=t.prototype.xnor,t.prototype.set=function(t,e){return e===!1?this.unset(t):0>t?this:(this.value|=1<<t,this)},t.prototype.unset=function(t){return 0>t?this:(this.value&=~(1<<t),this)},t.prototype.get=function(t){return 0>t?!1:(this.value&1<<t)>0},t.prototype.toggle=function(t){return this.set(t,!this.get(t)),this},t.prototype.swap=function(t,e){if(0>t||0>e)return this;Array.isArray(t)&&(e=t.pop(),t=t.shift());var n=this.copy();return this.set(e,n.get(t)),this.set(t,n.get(e)),this},t.prototype.equals=function(e){return e instanceof t&&(e=e.valueOf()),this.value===e},t.prototype.setValue=function(e){return e instanceof t&&(e=e.valueOf()),this.value=e,this},t.prototype.setRange=function(e,n){return 0>e||0>n?this:(this.value|=t.xor((1<<e)-1,(1<<n<<1)-1),this)},t.prototype.unsetRange=function(e,n){return 0>e||0>n?this:(this.value&=~t.xor((1<<e)-1,(1<<n<<1)-1),this)},t.prototype.toggleRange=function(e,n){if(0>e||0>n)return this;var r=t.mask(e,n);return this.value=this.copy().not().and(r).or(this.copy().and(t.not(r))).valueOf(),this},t.prototype.mask=function(e,n){return this.and(t.mask(e,n)),this},t.prototype.clear=function(e,n){return this.and(t.not(t.mask(e,n))),this};var e=this;"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=t),exports.Bitwise=t):e.Bitwise=t,"function"==typeof define&&define.amd&&define("bitwise",[],function(){return t})}).call(this); | ||
//# sourceMappingURL= |
@@ -1,2 +0,2 @@ | ||
// Bitwise.js 1.1.0 | ||
// Bitwise.js 1.1.1 | ||
// Bitwise may be freely distributed under the MIT license. | ||
@@ -35,3 +35,3 @@ | ||
// Current version. | ||
Bitwise.VERSION = '1.1.0'; | ||
Bitwise.VERSION = '1.1.1'; | ||
@@ -38,0 +38,0 @@ Bitwise.not = function(value) { |
@@ -51,3 +51,3 @@ { | ||
"readme": "ERROR: No README data found!", | ||
"version": "1.1.0" | ||
"version": "1.1.1" | ||
} |
@@ -88,7 +88,7 @@ Node.js: bitwise-operation | ||
Truth table: | ||
| a | NOT a | | ||
| --|-------| | ||
| 0 | 1 | | ||
| 1 | 0 | | ||
Truth table: | ||
| a | NOT a | | ||
| --|-------| | ||
| 0 | 1 | | ||
| 1 | 0 | | ||
@@ -146,9 +146,9 @@ Example: | ||
Truth table: | ||
| a | b | a NAND b | | ||
|---|---|----------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 1 | | ||
| 1 | 0 | 1 | | ||
| 1 | 1 | 0 | | ||
Truth table: | ||
| a | b | a NAND b | | ||
|---|---|----------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 1 | | ||
| 1 | 0 | 1 | | ||
| 1 | 1 | 0 | | ||
@@ -197,2 +197,3 @@ Example: | ||
=> 0b0110 | ||
``` | ||
@@ -206,9 +207,9 @@ ### nor() | ||
Truth table: | ||
| a | b | a NOR b | | ||
|---|---|---------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 0 | | ||
| 1 | 0 | 0 | | ||
| 1 | 1 | 0 | | ||
Truth table: | ||
| a | b | a NOR b | | ||
|---|---|---------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 0 | | ||
| 1 | 0 | 0 | | ||
| 1 | 1 | 0 | | ||
@@ -265,9 +266,9 @@ Example: | ||
Truth table: | ||
| a | b | a XNOR b | | ||
|---|---|----------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 0 | | ||
| 1 | 0 | 0 | | ||
| 1 | 1 | 1 | | ||
Truth table: | ||
| a | b | a XNOR b | | ||
|---|---|----------| | ||
| 0 | 0 | 1 | | ||
| 0 | 1 | 0 | | ||
| 1 | 0 | 0 | | ||
| 1 | 1 | 1 | | ||
@@ -274,0 +275,0 @@ Example: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33080
636