getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
}
Returns an image containing just the specified QA bits.

Args:
  image - The QA Image to get bits from.
  start - The first bit position, 0-based.
  end   - The last bit position, inclusive.
  name  - A name for the output image.