title: decimal to binary conversion in matlab
body: <p>the conversion of decimal to binary of text derived from a file is</p>
  
  <pre><code>temp=textread('E:\one.txt', '%1s', 'whitespace', '');  
  text = char(temp);                                                           
  y = zeros(length(text)*8,1);                                           
  for n = 1:1:length(text)  
  a=abs(text(n));                                                              
  f = 8*(n-1)+1;                                                          
  y(f:f+7,1)=(de2bi(a,8))';                                                   
  end
  disp('THE MAGNITUDE OF THE TEXT IS =');
  disp(a);
  disp(f);
  x=y';
  disp('THE BINARY BITS ARE');
  disp(x);
  </code></pre>
  
  <p>output of this program if file contained '1' stored in it</p>
  
  <pre><code>THE MAGNITUDE OF THE TEXT IS =
  49
  
   1
  
  THE BINARY BITS ARE
   1     0     0     0     1     1     0     0
  </code></pre>
  
  <p>if the number of bit of x is 8bit then i want first 3 bits displayed in a variable and rest 5 bits in another variable 
  i want a program for this in matlab.</p>
  
  <pre><code>eg x=00110011
  a=001
  b=10011 
  </code></pre>
  
  <p>encoding program</p>
  
  <pre><code>clc;
  clear all;
  temp=textread('E:\one.txt', '%1s', 'whitespace', '');  
  text = char(temp);                                                               
  y = zeros(length(text)*8,1);                                                
  for n = 1:1:length(text)  
      a=abs(text(n));                                                                 
      f = 8*(n-1)+1;                                                                    
      y(f:f+7,1)=(de2bi(a,8))';                                            
  end
  disp('THE MAGNITUDE OF THE TEXT IS =');
  disp(a);
  disp(f);
  x=y';
  disp('THE BINARY BITS ARE');
  disp(x);
  z=length(x);
  savefile='D:\mat\z.mat';
  save (savefile,'z','-MAT');
  disp('TOTAL NUMBER OF BITS =');
  disp(z);
  bk=input('ENTER THE NUMBER OF ROWS =');
  savefile='D:\mat\bk.mat';
  save (savefile,'bk','-MAT');
  c=z/bk;
  savefile='D:\mat\c.mat';
  save (savefile,'c','-MAT');
  k=1;
  for i=1:bk
      for j=1:c
          m(i,j)=x(k);
          k=k+1;
      end
  end
  %disp(m(i,j));
  disp('THE MESSAGE BITS ARE ');
  disp(m);
  savefile='D:\mat\m.mat';
  save (savefile,'m','-MAT');
  m_tot=(size(m,1)*size(m,2));
  savefile='D:\mat\m_tot.mat';
  save (savefile,'m_tot','-MAT');
  savefile='D:\mat\r1.mat';
  r1=[randperm(bk),randperm(bk)];
  save (savefile,'r1','-MAT');
  disp(r1);
  savefile='D:\mat\r2.mat';
  r2=[randperm(bk),randperm(bk)];
  save (savefile,'r2','-MAT');
  disp(r2);
  savefile='D:\mat\f(1).mat';
  f1= randint(1,1,[1,bk]);
  save (savefile,'f1','-MAT');
  savefile='D:\mat\en.mat';
  en(1,:)=m(f1,:);
  save (savefile,'en','-MAT');
  disp('DIRECTLY ASSIGNED BLOCK IS');
  disp(f1);
  for w=1:(length(r1))
      en(w+1,:)=xor((m(r1(w),:)),(m(r2(w),:)));
      disp('THE EXORED BLOCKS ARE= ');
      disp(r1(w));
      disp(r2(w));
  end
  disp('THE ENCODED BITS ARE');
  disp(en);
  en_tot=(size(en,1)*size(en,2));
  disp('tot no of encoded bits');
  disp(en_tot);
  save (savefile,'en_tot','-MAT');
  savefile='D:\mat\en_tot.mat';
  </code></pre>
  
  <p>the variable en should be split based on hop count same as u did with variable x.</p>