Encode n significant bits of a group of values

someone please help me here how it implemented in c/c++?
Given an array of unsigned bytes of arbitary length. Each of these bytes are of n bits in resolution, which means value range lies between 0 and 2^n-1. These values should be packed to another array of bytes, so that the length of new array is roundup(nl/8 ), where l is the length of input array and 1<=n<=8
For e.g. n=4, l=2 input=[00001011, 00001111] output=[10111111]
n=6, l=2 input=[00101011, 00111111] output=[10101111,11110000]
implement two functions
typedef BYTE char
//encode “in”, whose length is “length” and has “resolution” bits. Returns the length of enoded array int encode(BYTE
in, int length, BYTE resolution, BYTE* out); //decode “in”. Returns the length of decoded array int decode(BYTE* in, int length, BYTE resolution, BYTE* out);
//the following test condition should be met for all conditions. BYTE testInput[3]={1,2,3}; BYTE encoded[3];BYTE decoded[3];
int encodeLength=encode(testInput, 3, 2, out); decode(out, encodeLength, 2, decoded);
if (areArraysEqual(testInput, decoded)) { //Should be success. }