예제 #1
0
 /**
  * Return an unsigned short read from the data.
  *
  * @param
  *            int the offset into the data. An offset of zero will
  *            return the first short available in the current allowed window.
  *            The last valid offset is equal to {@link getSize()}-2. Invalid
  *            offsets will result in a {@link PelDataWindowOffsetException}
  *            being thrown.
  *
  * @return int the unsigned short found at offset.
  */
 public function getShort($o = 0)
 {
     /*
      * Validate the offset+1 to see if we can safely get two bytes ---
      * this throws an exception if offset is out of range.
      */
     $this->validateOffset($o);
     $this->validateOffset($o + 1);
     /* Translate the offset into an offset into the data. */
     $o += $this->start;
     /* Return an unsigned short. */
     return PelConvert::bytesToShort($this->data, $o, $this->order);
 }
예제 #2
0
 function testShortBig()
 {
     $o = PelConvert::BIG_ENDIAN;
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 0, $o), 0x0);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 1, $o), 0x0);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 2, $o), 0x0);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 3, $o), 0x1);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 4, $o), 0x123);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 5, $o), 0x2345);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 6, $o), 0x4567);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 7, $o), 0x6789);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 8, $o), 0x89ab);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 9, $o), 0xabcd);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 10, $o), 0xcdef);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 11, $o), 0xefff);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 12, $o), 0xffff);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 13, $o), 0xffff);
     $this->assertEqual(PelConvert::bytesToShort($this->bytes, 14, $o), 0xffff);
 }