decodeVersionInformation static method
Version?
decodeVersionInformation(
- int versionBits
)
Implementation
static Version? decodeVersionInformation(int versionBits) {
int bestDifference = MathUtils.maxValue; // int.max
int bestVersion = 0;
for (int i = 0; i < _versionDecodeInfo.length; i++) {
final targetVersion = _versionDecodeInfo[i];
// Do the version info bits match exactly? done.
if (targetVersion == versionBits) {
return getVersionForNumber(i + 7);
}
// Otherwise see if this is the closest to a real version info bit string
// we have seen so far
final bitsDifference =
FormatInformation.numBitsDiffering(versionBits, targetVersion);
if (bitsDifference < bestDifference) {
bestVersion = i + 7;
bestDifference = bitsDifference;
}
}
// We can tolerate up to 3 bits of error since no two version info codewords will
// differ in less than 8 bits.
if (bestDifference <= 3) {
return getVersionForNumber(bestVersion);
}
// If we didn't find a close enough match, fail
return null;
}