function intToBase64x32(i: number, pad: boolean) {
  if (i < 0 || i >= 1 << 30) {
    throw new Error('out of range: ' + i);
  }
  var ret = '',
    pos = 0;
  while (!pad && (i & 63) === 0 && pos++ < 5) {
    i >>= 6;
  }
  while (pos++ < 5) {
    ret = BASE64.charAt(i & 63) + ret;
    i >>= 6;
  }
  return ret;
}
convert int to a Base64x32 number (right zeroes skipped)