"""
Class Encore CIS 211 w/ Joseph
bit_packing.py
Author: <NAME>
Updated: 05/20/2021
"""

from typing import Tuple


def pack(x: int, y: int, z: int) -> int:
    """
    Pack x, y, and z into fields of an 8-bit unsigned integer.
    x: bits 4..7 (4 bits)
    y: bits 2..3 (2 bits)
    z: bits 0..1 (2 bits)
    """
    # You'll want to use shifting and bitwise ORs (|).
    # FIXME


def unpack(word: int) -> Tuple[int, int, int]:
    """
    Unpacks 8-bit unsigned int into
    bits 4..7 => x, bits 2..3 => y, and bits 0..1 => z
    Returns (x, y, z) in a Tuple
    """
    # This time, you'd still want to do shifting, but with masks and bitwise ANDs (&).
    # FIXME


# Example code
word1 = pack(0b1011, 0b10, 0b11)    # (11, 2, 3) in decimal
print(bin(word1))                   # 0b10111011
print(unpack(word1))                # (11, 2, 3)

word2 = pack(0b0110, 0b00, 0b10)    # (6, 0, 2) in decimal
print(bin(word2))                   # 0b1100010 with an implied 0 at the front
print(unpack(word2))                # (6, 0, 2)
