Problem storing random number of bits to a byte.

Thank you for a brief explanation. So there are some problems with my concept or my limited knowlegde with arduino,

  1. As you said as an example...
    0 is represented by 00
    1 is represented by 10
    2 is represented by 11
    3 is represented by 110
    4 is represented by 011
    So arduino will store it as 1 byte so I have to read the high bits of a byte like for example for 1, B00000010, so I am storing this value in a byte variable "P" by shifting B00000010 << 6 , so the resultant is B10000000.
    Now I have to store the next value which is 3 for example which is B00000110 so now I have a problem that how can I know that the variable "P" have to store the value from index 2 so that the resultant will be B10110000, that is my problem...

The code below is that, I simply made a manual Huffman tree with specific frequencies. First I am serching for the highest frequency , then get its index number and if the sensor value is equal to that index it will store a specific compressed value. So after that I have to store it in a byte because arduino minimum data type you can play with is byte so I have to store it in byte efficiently, that is my problem I am facing.

byte Huff(byte K){
int freq[]={5,2,3,4,4,3,2,1};
int first = freq[0];
byte firt=0;
byte K=0;
byte secd=0;
byte thrd=0;
byte frth=0;
byte fift=0;
byte sixt=0;
byte sevt=0;
byte Code=B00000000;
byte chk=0;
int fir {};
 Serial.begin(9600);
 
 for(int i=1;i<8;i++){
   if(first<freq[i]){
     first=freq[i];
      firt=i;
      
      }
      if(first==freq[i+1]){
       chk=(i+1);
      
   }
   }
if(K==firt || K==chk){
 Code=B00000000;
}
   
   Serial.println(firt);
   Serial.print("chk: ");
   Serial.println(chk);
   int secnd=0;
   for(int i=0;i<8;i++){
     if(freq[i]>secnd && freq[i]<first){
       secnd=freq[i];
       secd=i;
     }
   }
     for(int i=0;i<8;i++){
     if(freq[i+1]==secnd){
       chk=(i+1);
       Serial.print("ma yeahn");
      Serial.print("chk: ");
   Serial.println(chk);
   }
   }
   if(K==secd || K==chk){
 Code=B00000011 ;
}
   Serial.println(secd);
   Serial.print("chk: ");
   Serial.println(chk);
    int third=0;
    for(int i=0;i<8;i++){
     if(freq[i]>third && freq[i]<secnd && freq[i]<first){
     third=freq[i];
      thrd=i;
   }
    }
         for(int i=0;i<8;i++){
   if(third==freq[i+1]){
       chk=(i+1);
   }
      
   }
   
     if(K==thrd || K==chk){
 Code=B00000001;
}
   Serial.println(thrd);
   Serial.print("chk: ");
   Serial.println(chk);
   int fourth=0;
   for(int i=0;i<8;i++){
     if(freq[i]>fourth && freq[i]<third && freq[i]<secnd && freq[i]<first){
     fourth=freq[i];
      frth=i;
   }
   }
        for(int i=0;i<8;i++){
   if(fourth==freq[i+1]){
       chk=(i+1);
   }
   }
     if(K==frth || K==chk){
 Code=B00000101;
}
  
   Serial.println(frth);
   Serial.print("chk: ");
   Serial.println(chk);
   int fifth=0;
    for(int i=0;i<8;i++){
     if(freq[i]>fifth && freq[i]<fourth && freq[i]<third && freq[i]<secnd && freq[i]<first){
     fifth=freq[i];
      fift=i;
   }
    }
         for(int i=0;i<8;i++){
   if(fifth==freq[i+1]){
       chk=(i+1);
      
   }
   }
     if(K==fift || K==chk){
 Code=00000111;
}

   Serial.println(fift);
   Serial.print("chk: ");
   Serial.println(chk);
   int sixth=0;
   for(int i=0;i<8;i++){
     if(freq>sixth && freq[i]<fifth && freq[i]<fourth && freq[i]<third && freq[i]<secnd && freq[i]<first){
     sixth=freq[i];
      sixt=i;
   }
   }
        for(int i=0;i<8;i++){
   if(sixth==freq[i+1]){
       chk=(i+1);
      
   }
   }
//      

//}
   Serial.println(sixt);
   Serial.print("chk: ");
   Serial.println(chk);

Serial.print("Code :");
Serial.println(Code);
return(Code);
}
for(byte i=8;i>0;i++){
 TE[i]=bitRead(HUF,i)
}
if(Code==0 || Code==1 || Code==2 || Code==3){
 HUF= Code << 6;
}
if(Code==4 || Code==5 || Code==6 || Code==7){
 HUF= Code << 5;
}
if(Code==8 || Code==9 || Code==10){
 Huf= Code << 4;
}
void loop(){
}