Convert int to char

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello
I need to send a binary value through ethernet, i´m using a library  2ForLife_W5100 in PSOC5LP.
My problem is that i need to convert a binary value to char to send. I´m trying to use this, but isn´t work:

itoa(exibe_AZ,total_AZ, 2);

The declaration:

    uint16 total_AZ = 0;
    uint16 total_EL = 0;
    char exibe_AZ[16];
    char exibe_EL[16];

Obs: I included stdlib.h

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The base you should use (last parameter in itoa) is ten(10) and not two(2)

   

 

   

Bob

0 Likes
SuMa_296631
Level 5
Level 5
50 replies posted 25 replies posted 10 replies posted

Presumably you will be sending 4 x 8-bit values that make up the (assumed) 32-bit integer, so what is to stop you sending each 8-bit value just as it is?

   

Something like:

   

sendByte( value & 0xff);
sendByte( (value >> 😎 & 0xff);
sendByte( (value >> 16) & 0xff);
sendByte( (value >> 24) & 0xff);

   

Susan

0 Likes