﻿//-->
eval("_system = System");var System={};eval("System = _system ? _system : {};");System._bitConverter=function(){this.IsLittleEndian;var cMask={};cMask[System.TypeCode.Boolean]=0x1;cMask[System.TypeCode.Byte]=0xFF;cMask[System.TypeCode.SByte]=0x7F;cMask[System.TypeCode.Int16]=0x7FFF;cMask[System.TypeCode.Int32]=0x7FFFFFFF;cMask[System.TypeCode.UInt16]=0xFFFF;cMask[System.TypeCode.UInt32]=0xFFFFFFFF;var sBits={};sBits[System.TypeCode.Boolean]=1;sBits[System.TypeCode.Byte]=8;sBits[System.TypeCode.SByte]=8;sBits[System.TypeCode.Int16]=16;sBits[System.TypeCode.Int32]=32;sBits[System.TypeCode.UInt16]=16;sBits[System.TypeCode.UInt32]=32;this.GetBytes=function(value,typeCode){switch(typeof(value)){case "boolean":return(value)?[1]:[0];break;case "number":switch(typeCode){case System.TypeCode.Single:return this.GetBytesFromNumber(value,32);break;case System.TypeCode.Double:return this.GetBytesFromNumber(value,64);break;case System.TypeCode.Int16:case System.TypeCode.UInt16:return this.GetBytesFromInt16(value);break;case System.TypeCode.Int32:case System.TypeCode.UInt32:return this.GetBytesFromInt32(value);break;default:return this.GetBytesFromInt32(value);break;}break;case "object":var start=0;var end=value.length;switch(typeCode){case System.TypeCode.Single:return this.GetBytesFromNumber(value,32);break;case System.TypeCode.Double:return this.GetBytesFromNumber(value,64);break;case System.TypeCode.Int16:case System.TypeCode.UInt16:case System.TypeCode.Int32:case System.TypeCode.UInt32:return this.GetBytesFromIntegerArrayLe(value,start,end,typeCode);break;default:return this.GetBytesFromIntegerArrayLe(value,start,end,typeCode);break;}break;default:break;}};this.ToSingle=function(value,startIndex){var bytes=value.slice(startIndex,startIndex+4);return this.ToNumber(bytes);};this.ToDouble=function(value,startIndex){var bytes=value.slice(startIndex,startIndex+8);return this.ToNumber(bytes);};this.ToBoolean=function(value,startIndex){return(value[startIndex]&0x1)?true:false;};this.ToInt16Le=function(value,startIndex){return this.ToInt16ArrayLe(value,startIndex,2)[0];};this.ToInt16Be=function(value,startIndex){return this.ToInt16ArrayBe(value,startIndex,2)[0];};this.ToInt16=this.ToInt16Le;this.ToUInt16Le=function(value,startIndex){return this.GetUnsigned(this.ToInt16Le(value,startIndex),System.TypeCode.Int16);};this.ToUInt16Be=function(value,startIndex){return this.GetUnsigned(this.ToInt16Be(value,startIndex),System.TypeCode.Int16);};this.ToUInt16=this.ToUInt16Le;this.ToInt32Le=function(value,startIndex){return this.ToInt32ArrayLe(value,startIndex,4)[0];};this.ToInt32Be=function(value,startIndex){return this.ToInt32ArrayBe(value,startIndex,4)[0];};this.ToInt32=this.ToInt32Le;this.ToUInt32Le=function(value,startIndex){return this.GetUnsigned(this.ToInt32Le(value,startIndex),System.TypeCode.Int32);};this.ToUInt32Be=function(value,startIndex){return this.GetUnsigned(this.ToInt32Be(value,startIndex),System.TypeCode.Int32);};this.ToUInt32=this.ToUInt32Le;this.GetBytesFromInt16=function(value){var bytes=new Array(2);for(var i=0;i<2;i++)bytes[i]=(value>>i*8)&0xff;return bytes;};this.GetBytesFromInt32=function(value){var bytes=new Array(4);for(var i=0;i<4;i++)bytes[i]=(value>>i*8)&0xff;return bytes;};this.GetBytesFromIntegerArrayLe=function(array,startIndex,count,typeCode){var sizeBits=sBits[typeCode];var sizeBytes=((sizeBits)?sizeBits:32)/8;startIndex=(startIndex)?startIndex:0;count=(count)?count:array.length-startIndex;var bytes=new Array(count*sizeBytes);var i,b;var length=startIndex+count;for(i=startIndex;i<length;i++){for(b=0;b<sizeBytes;b++){bytes[i*sizeBytes+b]=(array[i]>>b*8)&0xff;}}return bytes;};this.GetBytesFromIntegerArrayBe=function(array,startIndex,count,typeCode){var sizeBits=sBits[typeCode];var sizeBytes=((sizeBits)?sizeBits:32)/8;startIndex=(startIndex)?startIndex:0;count=(count)?count:array.length-startIndex;var bytes=new Array(count*sizeBytes);var i,b;var length=startIndex+count;for(i=startIndex;i<length;i++){for(b=0;b<sizeBytes;b++){bytes[i*sizeBytes+sizeBytes-1-b]=(array[i]>>b*8)&0xff;}}return bytes;};this.GetBytesFromIntegerArray=this.GetBytesFromIntegerArrayLe;this.GetBitsLe=function(array,typeCode){var length=array.length;var bpn=sBits[typeCode];bpn=(bpn)?bpn:32;var bits=new Array(length*bpn);for(var i=0;i<length;i++){var value=array[i];for(var b=0;b<bpn;b++){bits[i*bpn+b]=value&0x1;value=value>>1;}}return bits;};this.GetBitsBe=function(array,typeCode){var length=array.length;var bpn=sBits[typeCode];bpn=(bpn)?bpn:32;var bits=new Array(length*bpn);for(var i=0;i<length;i++){var value=array[i];for(var b=0;b<bpn;b++){bits[i*bpn+bpn-1-b]=value&0x1;value=value>>1;}}return bits;};this.GetBits=this.GetBitsLe;this.GetUnsigned=function(value,typeCode){var results;var umask=cMask[typeCode+1];if(typeof(value)=="number"){results=((value&umask)<<0)>>>0;}else{umask=cMask[typeCode+1];var length=value.length;results=new Array(length);for(var i=0;i<length;i++){var n=value[i];results[i]=((n&umask)<<0)>>>0;}}return results;};this.GetSigned=function(value,typeCode){var results;var umask=cMask[typeCode];var smask=cMask[typeCode-1];if(typeof(value)=="number"){results=(value>smask)? -(-value&umask):n;}else{var length=value.length;results=new Array(length);for(var i=0;i<length;i++){var n=value[i];results[i]=(n>smask)? -(-n&umask):n;}}return results;};this.ToInt16ArrayLe=function(value,startIndex,count){var charSize=8;var array=Array(count/2);var mask=(1<<charSize)-1;count=(count)?count:value.length;var length=count*charSize;for(var i=0;i<length;i+=charSize){array[i>>4]|=(value[startIndex+(i/charSize)]&mask)<<(i%16);}array=this.GetSigned(array,System.TypeCode.UInt16);return array;};this.ToInt16ArrayBe=function(value,startIndex,count){var charSize=8;var array=Array();var mask=(1<<charSize)-1;count=(count)?count:value.length;var length=count*charSize;for(var i=0;i<length;i+=charSize){array[i>>4]|=(value[startIndex+(i/charSize)]&mask)<<(16-charSize-i%16);}return array;};this.ToInt32ArrayLe=function(value,startIndex,count){var charSize=8;var array=Array();var mask=(1<<charSize)-1;count=(count)?count:value.length;var length=count*charSize;for(var i=0;i<length;i+=charSize){array[i>>5]|=(value[startIndex+(i/charSize)]&mask)<<(i%32);}return array;};this.ToInt32ArrayBe=function(value,startIndex,count){var charSize=8;var array=Array();var mask=(1<<charSize)-1;count=(count)?count:value.length;var length=count*charSize;for(var i=0;i<length;i+=charSize){array[i>>5]|=(value[startIndex+(i/charSize)]&mask)<<(32-charSize-i%32);}return array;};this.ToInt32Array=this.ToInt32ArrayLe;this.Int16EndianSwap=function(x){x=(x>>8)|(x<<8);return x;};this.Int32EndianSwap=function(x){x=(x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24);return x;};this.Int64EndianSwap=function(x){x=(x>>56)|((x<<40)&0x00FF000000000000)|((x<<24)&0x0000FF0000000000)|((x<<8)&0x000000FF00000000)|((x>>8)&0x00000000FF000000)|((x>>24)&0x0000000000FF0000)|((x>>40)&0x000000000000FF00)|(x<<56);return x;};this.ToString=function(bytes,separator,format){var sb=new Array();var s=new String;if(!bytes)return;format=(format)?format:"X2";var len=parseInt(format.substr(1));var pfx="";for(var i=0;i<len;i++)pfx+="0";for(var i=0;i<bytes.length;i++){var b=bytes[i]&0xFF;var hex=b.toString(16).toUpperCase();sb.push(pfx.substr(0,len-hex.length)+hex);}var sep=(typeof(separator)=="undefined")?'-':separator;return sb.join(sep);};this.SemSingleToBytes=function(sign,exponent,mantissa){var B=new Array(4);mantissa=Math.pow(2,23)*mantissa+0.5;B[3]=0xFF&mantissa;B[2]=0xFF&(mantissa>>8);B[1]=0x7F&(mantissa>>16)|(exponent&1)<<7;B[0]=sign<<7|(exponent>>1);return B;};this.SemDoubleToBytes=function(sign,exponent,mantissa){var B=new Array(4);mantissa=Math.pow(2,52)*mantissa;B[3]=0xFFFF&mantissa;B[2]=0xFFFF&(mantissa>>16);mantissa/=Math.pow(2,32);B[1]=0xFFFF&mantissa;B[0]=sign<<15|exponent<<4|0x000F&(mantissa>>16);return this.GetBytesFromIntegerArrayBe(B,0,B.length,System.TypeCode.Int16);};this.GetBytesFromNumber=function(Qty,NumW){this.Number=Qty;var Bin;this.nb01="";var Inf={32:{d:0x7F,c:0x80,b:0,a:0},64:{d:0x7FF0,c:0,b:0,a:0}};var ExW={32:8,64:11}[NumW];var MtW=NumW-ExW-1;var sign;var exponent;var mantissa;if(isNaN(Qty)){Bin=Inf[NumW];Bin.a=1;sign=false;exponent=Math.pow(2,ExW)-1;mantissa=Math.pow(2,-MtW);}if(!Bin){sign=Qty<0||1/Qty<0;if(!isFinite(Qty)){Bin=Inf[NumW];if(this.Sign)Bin.d+=1<<(NumW/4-1);exponent=Math.pow(2,ExW)-1;mantissa=0;}}if(!Bin){exponent={32:127,64:1023}[NumW];mantissa=Math.abs(Qty);while(mantissa>=2){exponent++;mantissa/=2;}while(mantissa<1&&this.Exponent>0){exponent--;mantissa*=2;}if(exponent<=0){mantissa/=2;}if(NumW==32&&this.Exponent>254){Bin={d:sign?0xFF:0x7F,c:0x80,b:0,a:0};exponent=Math.pow(2,ExW)-1;mantissa=0;}}var array;if(!Bin){if(NumW==32)array=this.SemSingleToBytes(sign,exponent,mantissa);if(NumW==64)array=this.SemDoubleToBytes(sign,exponent,mantissa);}else{array=[Bin.a,Bin.b,Bin.c,Bin.d];if(NumW==64)array=this.GetBytesFromIntegerArrayBe(array,0,array.length,System.TypeCode.Int16);}return array.reverse();};this.ToNumber=function(value){var bytes=value.reverse();var bits=this.GetBitsBe(bytes,System.TypeCode.Byte);var BinStr=this.GetBitsBe(bytes,System.TypeCode.Byte).join('');var ExW={32:8,64:11}[BinStr.length];var M=BinStr.match(new RegExp("^(.)(.{"+ExW+"})(.*)$"));var sign=(bits[0]==1)?"-":"+";var denorm=(+M[2]==0);var expo=parseInt(M[2],2)-Math.pow(2,ExW-1)+1;var array=DecimalDigits(bits,ExW);array.unshift(+ !denorm,".");if(denorm)expo++;while(expo<0){expo++;Halve(array);}while(expo>0){expo--;Twice(array);}var value=sign+array.join("").replace(/(\d)0+$/,"$1");return+eval(value);};function Add(A,P){var C=0;var K=P.length;var T;while(K--){T=(A[K]|0)+P[K]+C;A[K]=T%10;C=T>9;}};function Halve(P){var C=0;var L=P.length;var T;for(var K=0;K<L;K++){if((T=P[K])!="."){T+=10*C;C=T&1;P[K]=T>>1;}}if(C)P[K]=5;};function DecimalDigits(bits,ExW){var A=[0];var P=[10];var index=ExW+1;var length=bits.length;for(var i=index;i<length;i++){Halve(P);if(bits[i]==1)Add(A,P);}return A;};function Twice(A){var K=A.length;C=0;T;while(K--){if((T=A[K])!="."){T=2*T+C;A[K]=T%10;C=T>9;}}if(C)A.unshift(1);};this._isLittleEndian=function(){var bytes=this.GetBytes(-1.5,System.TypeCode.Double);return(bytes[0]==0);};this.Initialize=function(){this.IsLittleEndian=this._isLittleEndian();};this.Initialize.apply(this,arguments);};System.BitConverter=new System._bitConverter();System.BitConverter.ToArrayDefinition=function(bytes,cols,format){var sb=new Array();var s="<br />\r\nvar a = [<br />\r\n";cols=(cols)?cols:8;format=(format)?format:"X4";var len=parseInt(format.substr(1));var pfx="";for(var i=0;i<len;i++)pfx+="0";for(var i=0;i<bytes.length;i++){var hex=bytes[i].toString(16).toUpperCase();sb.push(pfx.substr(0,len-hex.length)+hex);if(!((i+1)%cols)){s+="0x";s+=sb.join(", 0x");if(i<bytes.length-1)s+=",";s+="<br />\r\n";sb=new Array();}}if(sb.length>0){s+="0x";s+=sb.join(", 0x");s+="<br />\r\n";}s+="];";return s;}
