def get_binary_encoding(bit_num: int):
    """
    **Overview**:
        Implementation of binary encoding with nn.Embedding API.
    """
    # Generate a matrix with shape $$2^{B} \times B $$ where B is the bit_num.
    # Each row with index n contains the binary representation of n.
    location_embedding = []
    for n in range(2 ** bit_num):
        s = '0' * (bit_num - len(bin(n)[2:])) + bin(n)[2:]
        location_embedding.append(list(int(i) for i in s))
    mat = torch.FloatTensor(location_embedding)
    # Use the generated result as transformation..
    return torch.nn.Embedding.from_pretrained(mat, freeze=True, padding_idx=None)

    **Overview**:
        Implementation of binary encoding with nn.Embedding API.
    
chapter3_obs/encoding.py