Read a bit field starting at specified byte and bit, each numbered from 0. Bit numbering is from high to low, like this: getField bitIndex: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 Note that this is inverted with respect to the numbering scheme used in many GSM specs, which looks like this: GSM specs: 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 Note that some GSM specs use low-to-high and some use high-to-low numbering. G
| 490 | // Generally, where the BitVector class is used they use low-to-high numbering, |
| 491 | // which is rectified in the FEC classes by the byteswapping the BitVector before being used. |
| 492 | uint64_t ByteVector::getField2(size_t byteIndex, size_t bitIndex, unsigned lengthBits) const |
| 493 | { |
| 494 | ByteType *dp = mStart + byteIndex; |
| 495 | int len = (int) lengthBits; |
| 496 | BVASSERT(bitIndex >= 0 && bitIndex <= 7); |
| 497 | // Get first byte: |
| 498 | // This was for bitIndex running from low bit to high bit: |
| 499 | // int nbits = bitIndex+1; // Number of bits saved from byte. |
| 500 | // This is for bitIndex running from 0=>high bit to 7=>low bit: |
| 501 | int nbits = 8-bitIndex; // Number of bits saved from byte, ignoring len restriction. |
| 502 | // Example: bitIndex=3 => 0 | 0 | 0 | X | X | X | X | X => AND with 0x1f |
| 503 | |
| 504 | uint64_t accum = *dp++ & (0x0ff >> (8-nbits)); // Preserve right-most bits. |
| 505 | if (len < nbits) { accum >>= (nbits - len); return accum; } |
| 506 | len -= nbits; |
| 507 | |
| 508 | // Get the full bytes: |
| 509 | for (; len >= 8; len -= 8) { accum = (accum << 8) | *dp++; } |
| 510 | |
| 511 | // Append high bits of last byte: |
| 512 | if (len>0) { accum = (accum << len) | (*dp >> (8-len)); } |
| 513 | return accum; |
| 514 | } |
| 515 | |
| 516 | // This is static - there is no 'this' argument. |
| 517 | int ByteVector::compare(const ByteVector &bv1, const ByteVector &bv2) |
no outgoing calls
no test coverage detected