I would do bitmasking + bitshifting:
let a = 0b1100_0101
let a_high = (a and 0b1111_00000) shr 4
echo a_high # => 12 (0b1100)
i did not understand what is happening there,
There is nothing special. First it has not to be a template, a proc would do. And you have to know only masking and shifting. You shift the bits right, and then mask all but the lower 8 bits. Same as in C. Another way is casting to array of bytes and accessing the bytes as in