% This function converts a vector of binary numbers (binary_num) to a
% string of text letters (text)  Six binary bits are decoded to 1 letter, 
% so the input vector (binary_num) must be divisible by 6.

function [text] = binarydecode(binary_num)

num_length = length(binary_num);
text_output = '';
char_temp = '';

for x = 0:6:num_length-6,
   sub_string = num2str(binary_num(x+1:x+6));
   switch sub_string
      case {'0  0  0  0  0  0'}, char_temp = ' ';
      case {'0  0  0  0  0  1'}, char_temp = '0'; 
      case {'0  0  0  0  1  0'}, char_temp = '1'; 
      case {'0  0  0  0  1  1'}, char_temp = '2'; 
      case {'0  0  0  1  0  0'}, char_temp = '3'; 
      case {'0  0  0  1  0  1'}, char_temp = '4'; 
      case {'0  0  0  1  1  0'}, char_temp = '5'; 
      case {'0  0  0  1  1  1'}, char_temp = '6'; 
      case {'0  0  1  0  0  0'}, char_temp = '7'; 
      case {'0  0  1  0  0  1'}, char_temp = '8'; 
      case {'0  0  1  0  1  0'}, char_temp = '9'; 
      case {'0  0  1  0  1  1'}, char_temp = '.'; 
      case {'0  0  1  1  0  0'}, char_temp = ','; 
      case {'0  0  1  1  0  1'}, char_temp = '!'; 
      case {'0  0  1  1  1  0'}, char_temp = '?'; 
      case {'0  0  1  1  1  1'}, char_temp = '"'; 
      case {'0  1  0  0  0  0'}, char_temp = ':'; 
      case {'0  1  0  0  0  1'}, char_temp = ';'; 
      case {'0  1  0  0  1  0'}, char_temp = '#'; 
      case {'0  1  0  0  1  1'}, char_temp = '%'; 
      case {'0  1  0  1  0  0'}, char_temp = '*'; 
      case {'0  1  0  1  0  1'}, char_temp = '+'; 
      case {'0  1  0  1  1  0'}, char_temp = '='; 
      case {'0  1  0  1  1  1'}, char_temp = '/'; 
      case {'0  1  1  0  0  0'}, char_temp = '\'; 
      case {'0  1  1  0  0  1'}, char_temp = '-';
      case {'0  1  1  0  1  0'}, char_temp = '_';
      case {'0  1  1  0  1  1'}, char_temp = '@'; 
      case {'0  1  1  1  0  0'}, char_temp = '$'; 
      case {'0  1  1  1  0  1'}, char_temp = '('; 
      case {'0  1  1  1  1  0'}, char_temp = ')'; 
      case {'0  1  1  1  1  1'}, char_temp = '{'; 
      case {'1  0  0  0  0  0'}, char_temp = '}'; 
      case {'1  0  0  0  0  1'}, char_temp = '~'; 
      case {'1  0  0  0  1  0'}, char_temp = '^'; 
      case {'1  0  0  0  1  1'}, char_temp = '<'; 
      case {'1  0  0  1  0  0'}, char_temp = '>'; 
      case {'1  0  0  1  0  1'}, char_temp = '&'; 
      case {'1  0  0  1  1  0'}, char_temp = 'a'; 
      case {'1  0  0  1  1  1'}, char_temp = 'b'; 
      case {'1  0  1  0  0  0'}, char_temp = 'c'; 
      case {'1  0  1  0  0  1'}, char_temp = 'd'; 
      case {'1  0  1  0  1  0'}, char_temp = 'e'; 
      case {'1  0  1  0  1  1'}, char_temp = 'f'; 
      case {'1  0  1  1  0  0'}, char_temp = 'g'; 
      case {'1  0  1  1  0  1'}, char_temp = 'h'; 
      case {'1  0  1  1  1  0'}, char_temp = 'i'; 
      case {'1  0  1  1  1  1'}, char_temp = 'j'; 
      case {'1  1  0  0  0  0'}, char_temp = 'k'; 
      case {'1  1  0  0  0  1'}, char_temp = 'l'; 
      case {'1  1  0  0  1  0'}, char_temp = 'm'; 
      case {'1  1  0  0  1  1'}, char_temp = 'n'; 
      case {'1  1  0  1  0  0'}, char_temp = 'o'; 
      case {'1  1  0  1  0  1'}, char_temp = 'p'; 
      case {'1  1  0  1  1  0'}, char_temp = 'q'; 
      case {'1  1  0  1  1  1'}, char_temp = 'r'; 
      case {'1  1  1  0  0  0'}, char_temp = 's'; 
      case {'1  1  1  0  0  1'}, char_temp = 't';
      case {'1  1  1  0  1  0'}, char_temp = 'u'; 
      case {'1  1  1  0  1  1'}, char_temp = 'v';      
      case {'1  1  1  1  0  0'}, char_temp = 'w'; 
      case {'1  1  1  1  0  1'}, char_temp = 'x'; 
      case {'1  1  1  1  1  0'}, char_temp = 'y';
      case {'1  1  1  1  1  1'}, char_temp = 'z';
      otherwise char_temp = 'A';
         
   end
   text_output = [text_output char_temp];
end

text = text_output;
