title: Hex to ASCII in c
body: <p>Here is my logic, to convert HEX to ASCII conversion in C:</p>
  
  <pre><code>for (i=0;i&lt;ArraySize;i++)
      {
          /*uses a bitwise AND to take the top 4 bits from the byte,
           0xF0 is 11110000 in binary*/
          char1 = Tmp[i] &amp; 0xf0;
          char1 = char1 &gt;&gt; 4;
          /*bit-shift the result to the right by four bits (i.e. quickly divides by 16)*/
          if (char1 &gt;9)
          {
              char1 = char1 - 0xa;
              char1 = char1 + 'A';
          }
          else
          char1 = char1 + '0';
          Loc[j]=char1;
          j++;
          /*means use a bitwise AND to take the bottom four bits from the byte,
          0x0F is 00001111 in binary*/
          char1 = Tmp[i] &amp; 0x0f;
          if (char1 &gt;9)
          {
              char1 = char1 - 0xa;
              char1 = char1 + 'A';
          }
          else
          char1 = char1 + '0';
          Loc[j]=char1;
          j++;
          Loc[j]=0;
      }
  </code></pre>
  
  <p>Temp and Loc are string buffers. Defined and has data. It is not working properly. I am reading data in temp from some file (sample fread). It stop reading file at particular point. If I change first </p>
  
  <blockquote>
    <p>0xf0 </p>
  </blockquote>
  
  <p>to  </p>
  
  <blockquote>
    <p>0x0f</p>
  </blockquote>
  
  <p>Here is how file is being read:</p>
  
  <pre><code>BytesRead = fread (Tmp,1,Bytes,PrcFile);
  </code></pre>
  
  <p>Then it reads whole file. I am not able to find what is missing. Can you please help me in this regards.
  Thanks</p>