Splitting packed bits problem

Hey! I’m making a game in which there may be thousands of NPCs. Currently I’m working on replication of NPCs position and I have a problem with bit packing.

I’m following @Atrazine post where he explains how he reduced his network bandwidth.
Right now I’m sending four integers over client and I want to send only two using bit packing.

The problem is that I don’t know how to split bits over two integers and then merge them again.

for example:
I want to split a number “3” into two integers:

local first_bits = 0b0000_0000_0001_1111
local second_bits = 0b1100_0000_0000_0000

and after that I want to reconstruct it again.

I was trying to make it by myself or to find similar posts but nothing worked. :slightly_frowning_face:
I have really little knowlege about bits. Please help! :smiley: