/**
  * <p>Reads version information from one of its two locations within the QR Code.</p>
  *
  * @return {@link Version} encapsulating the QR Code's version
  * @throws FormatException if both version information locations cannot be parsed as
  * the valid encoding of version information
  */
 function readVersion()
 {
     if ($this->parsedVersion != null) {
         return $this->parsedVersion;
     }
     $dimension = $this->bitMatrix->getHeight();
     $provisionalVersion = ($dimension - 17) / 4;
     if ($provisionalVersion <= 6) {
         return Version::getVersionForNumber($provisionalVersion);
     }
     // Read top-right version info: 3 wide by 6 tall
     $versionBits = 0;
     $ijMin = $dimension - 11;
     for ($j = 5; $j >= 0; $j--) {
         for ($i = $dimension - 9; $i >= $ijMin; $i--) {
             $versionBits = $this->copyBit($i, $j, $versionBits);
         }
     }
     $theParsedVersion = Version::decodeVersionInformation($versionBits);
     if ($theParsedVersion != null && $theParsedVersion->getDimensionForVersion() == $dimension) {
         $this->parsedVersion = $theParsedVersion;
         return $theParsedVersion;
     }
     // Hmm, failed. Try bottom left: 6 wide by 3 tall
     $versionBits = 0;
     for ($i = 5; $i >= 0; $i--) {
         for ($j = $dimension - 9; $j >= $ijMin; $j--) {
             $versionBits = $this->copyBit($i, $j, $versionBits);
         }
     }
     $theParsedVersion = Version::decodeVersionInformation($versionBits);
     if ($theParsedVersion != null && $theParsedVersion->getDimensionForVersion() == $dimension) {
         $this->parsedVersion = $theParsedVersion;
         return $theParsedVersion;
     }
     throw FormatException::getFormatInstance();
 }