Hi all, I'm working on a project that use Microchip PIC18 series. The only compiler I have is the C18 provided freely from microchip
Anyway it is a simple question. I have an unsigned int that I wish to break it into 2 char that I could send through UART using the putcUSART function. I'm thinking of using the union struct or something, but I can't find references online.
Anyone knows how to do it? Thanks
typedef union combo {
int Int;
char Char[2];
} Tcombo;
Tcombo x;
x.Int = 0x1234;
x.Char[0] == 0x12; // NOTE! Only if the compiler uses big endian -
x.Char[1] == 0x34; // otherwise it is the other way around.
The Tcombo thing is exactly what I want, I'm thinking the union method is more efficient than taking division and mod? (not sure)
Thank you both for the help =)
The Tcombo thing is exactly what I want, I'm thinking the union method is more efficient than taking division and mod? (not sure)
Thank you both for the help =)
Have a look at this thread to see you question answered: **broken link removed**
C18 would not actually do the division or shifting. Why don't you try compiling those code snippets to see what is actually done? I do know about the union method, but I prefer the other two methods.