/****************************************************/
/*32-bit Binary to ASCII Hexadecimal Conversion Code*/
/*The fast and compact method by Cypress            */
/*PIC32MX795F512L-80I/PF                            */
/****************************************************/

#include <p32xxxx.h>

int d_hex[8];

void Binary2ASCIIHex(int i_hex)
{
    unsigned t_hex;
    
    //digit 0
    t_hex = i_hex;
    d_hex[0] = t_hex & 0xf;
    
    //digit 1
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[1] = t_hex & 0xf;

    //digit 2
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[2] = t_hex & 0xf;

    //digit 3
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[3] = t_hex & 0xf;

    //digit 4
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[4] = t_hex & 0xf;

    //digit 5
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[5] = t_hex & 0xf;

    //digit 6
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[6] = t_hex & 0xf;

    //digit 7
    i_hex = i_hex>>4;
    t_hex = i_hex;
    d_hex[7] = t_hex & 0xf;

    //hex digits are separated
    //now convert to ascii
    int h;
    
    for(h=0;h<=7;h++)
    {
        if(d_hex[h] > 9)
        {
            d_hex[h] = d_hex[h] + 87;
        }
        else
        {
            d_hex[h] = d_hex[h] + 48;
        }
    }
    
    return;
}
