Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-343

Int4 Pair Packing

Problem

Pack two unsigned 4-bit codes into one byte: low nibble = values[0], high nibble = values[1], returning values[0] | (values[1] << 4). Inputs are masked to 4 bits.

The signature is int4_pair_pack(values).

Hint

The low nibble sits in bits 0-3 and the high nibble in bits 4-7.

Test cases

case 1
in: [[3,5]]
expected: 83
case 2
in: [[0,15]]
expected: 240
case 3
in: [[15,0]]
expected: 15
case 4
in: [[10,10]]
expected: 170
Starter codePython
def int4_pair_pack(values):
    # Your code here
    pass

4 test cases · run your code against them in the editor