looking for itox() function, conversion of integer to hex string (no printf or stdio.h).

There is itoa() function from standard library that do this.

I'm using C28x device in embedded c (using code composer).

I'm looking for integer to hex string conversion

Can you suggest?

Example

UINT16 i;
INT32 RXdataRAW[10];    // contain INT32 data from ADC device
char UART_ASCII[12];       // for string formating.
for (i=0; i<10; i++)
{
UARTB_String("CH1 0x");
ltoa(RXdataRAW(i), UART_ASCII);
UARTB_Msg_LFCR(UART_ASCII);
}
Richard PayneChief Technology EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
How are UARTB_String,  UARTB_Msg_LFCR, and ltoa defined?
0
Richard PayneChief Technology EngineerAuthor Commented:
itoa() come from standard library (stdlib.h), ie
int       ltoa(long val, char *buffer);

UARTB function is related to UARTB port of C28x based device. It take string in char array to UARTB port. That all you need to know....
0
ozoCommented:
itoa is not standard.
There is a non-standard
char *  itoa ( int value, char * str, int base );
that is supported by some compilers,
but your example used ltoa
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Richard PayneChief Technology EngineerAuthor Commented:
Hmm interesting

The data being used is 32 bit, the C28x device is 16 bit in memory but 32 bit core.

Thus the reason for ltoa() which is used for decimal ASCII, I need hex ASCII, they do not have base in ltoa()
0
ozoCommented:
static char d[]="0123456789abcdef";
void ltoa(unsigned long l,char a[9]){
  a[8]=0;
  for(int i=8;i>0;){
    a[--i]=d[l&0xf];
    l>>=4;
  }
}
int main(){
  char a[9];
  ltoa(0x12345678,a);
  printf("%s\n",a);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sarabandeCommented:
or

char * intToHex(unsigned int x, char buf[], int sizbuf)
{      
    buf[--sizbuf] = '\0';
    while (sizbuf > 0 && x != 0)
    {
        unsigned char hexdig = (unsigned char)(x%16);
        buf[--sizbuf] =  (hexdig < 10)? ('0'+hexdig) : ('a' + hexdig-10);
        x /= 16;
    }
    return &buf[sizbuf];
}

int main()
{
    char buf[32] = { 0 };
    char * p = intToHex(0x1357ACEF, buf, 32);
    std::cout << p << std::endl;
    return 0;
}

Open in new window


Sara
0
Richard PayneChief Technology EngineerAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.