-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsByte.min.js
1 lines (1 loc) · 1.09 KB
/
jsByte.min.js
1
function Byte(t,e,i){return this.constructor!=Byte?new Byte(t,e,i):(this._s="undefined"==typeof i?8:i,this._i=parseInt(t,e),void this.setBits())}Byte.prototype.getBit=function(t){return this._b[this._s-1-t]},Byte.prototype.setBit=function(t,e){return this._b[this._s-1-t]=String(e),this.setInt()},Byte.prototype.setBits=function(){return this._b=this._i.toString(2).split(""),Array().unshift.apply(this._b,Array(this._s-this._b.length).fill("0")),this},Byte.prototype.setInt=function(){return this._i=parseInt(this.toString(),2),this},Byte.prototype.invert=function(){return this._i=~this._i&Math.pow(2,this._b.length)-1,this.setBits()},Byte.prototype.flip=function(){return this._b=this._b.reverse(),this.setInt()},Byte.prototype.toBase=function(t){return this._i.toString(t)},Byte.prototype.toString=function(){return this._b.join("")},Byte.prototype.toArray=function(){return this._b},Byte.prototype.toInt=Byte.prototype.valueOf=function(){return this._i},Number.prototype.toByte=String.prototype.toByte=function(t,e){return new Byte(this,t,e)},Array.prototype.toByte=function(t){return new Byte(this.join(""),2,t)};