from typing import Sequence
from typing import Tuple


def pack_to_bitfield(ints_and_num_bits: Sequence[Tuple[int, int]]) -> int:
  """Packs a sequence of ints into a single int which acts like a bitfield.

  Args:
    ints_and_num_bits: Sequence of tuples each containing an int and the max
      number of bits required to represent that int.

  Returns:
    A single arbitrary precision int with all the passed ints packed into it.
  """
  int_rep = 0
  bits_count = 0
  for sub_int_rep, num_bits in ints_and_num_bits:
    for i in range(num_bits):
      if sub_int_rep & (1 << i):
        int_rep |= (1 << (bits_count + i))
    bits_count += num_bits
  return int_rep