import struct


def encode_nibbles(val, val2):
    """Encode two values as two nibbles in a byte

    Specs:
        * **Nibble**:   MSN  LSN

        * **Byte**:   0b0000 0000

        * **Indexes**:  7654 3210

        * **Values**:   val2 val

    Requirement:
        * Only values (0-15) allowed
    """
    assert any([v > 2**4 - 1 for v in [val, val2]]) is False, 'Nibble value too big, only values (0-15) allowed'

    # shift 4 bits to the left
    fullbyte = (val2 << 4) + val
    return struct.pack('B', fullbyte)