from typing import List


def val2bits(val: int, nbits: int) -> List[int]:
  """Convert decimal integer to list of {0, 1}."""

  # We return the bits in order high to low. For example,
  # the value 6 is being returned as [1, 1, 0].
  return [int(c) for c in format(val, f'0{nbits}b')]