Changeset 30094

Show
Ignore:
Timestamp:
02/15/09 21:45:40 (4 years ago)
Author:
fujidig
Message:

ビットシフトを使うように変更

Location:
lang/javascript/hsp-on-js/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/hsp-on-js/trunk/src/binary-parser.js

    r28714 r30094  
    2323        p.prototype = { 
    2424                readChar: function() { 
    25                         this.checkBuffer(this.offset + 1); 
    26                         var result = this.buffer[this.buffer.length - this.offset - 1]; 
    27                         if(result & 0x80) result -= 0x100; 
    28                         ++ this.offset; 
    29                         return result; 
     25                        return this.readUChar() << 24 >> 24; 
    3026                }, 
    3127                readUChar: function() { 
     
    3632                }, 
    3733                readShort: function() { 
    38                         this.checkBuffer(this.offset + 2); 
    39                         var result = this.buffer[this.buffer.length - this.offset - 1]; 
    40                         result |= this.buffer[this.buffer.length - this.offset - 2] << 8; 
    41                         if(result & 0x8000) result -= 0x10000; 
    42                         this.offset += 2; 
    43                         return result; 
     34                        return this.readUShort() << 16 >> 16; 
    4435                }, 
    4536                readUShort: function() { 
     
    5142                }, 
    5243                readInt24: function() { 
    53                         this.checkBuffer(this.offset + 3); 
    54                         var result = this.buffer[this.buffer.length - this.offset - 1]; 
    55                         result |= this.buffer[this.buffer.length - this.offset - 2] << 8; 
    56                         result |= this.buffer[this.buffer.length - this.offset - 3] << 16; 
    57                         if(result & 0x800000) result -= 0x1000000; 
    58                         this.offset += 3; 
    59                         return result; 
     44                        return this.readUInt24() << 8 >> 8; 
    6045                }, 
    6146                readUInt24: function() { 
     
    7762                }, 
    7863                readUInt: function() { 
    79                         this.checkBuffer(this.offset + 4); 
    80                         var result = this.buffer[this.buffer.length - this.offset - 1]; 
    81                         result |= this.buffer[this.buffer.length - this.offset - 2] << 8; 
    82                         result |= this.buffer[this.buffer.length - this.offset - 3] << 16; 
    83                         result += this.buffer[this.buffer.length - this.offset - 4] * 0x1000000; 
    84                         this.offset += 4; 
    85                         return result; 
     64                        return this.readInt() >>> 0; 
    8665                }, 
    8766                readDouble: function() { 
  • lang/javascript/hsp-on-js/trunk/src/formatter.js

    r30092 r30094  
    9292        convertInt: function(val, flags, width, prec, signed, radix, pre) { 
    9393                if(!signed) { 
    94                         if(val & 0x80000000) val += 0x100000000; 
     94                        val >>>= 0; 
    9595                } 
    9696                var isNegative = val < 0;