Forum Discussion
Altera_Forum
Honored Contributor
15 years agoC CODE Integer as ASCII to printf string...HELP!!!
Hi all, As like the title, now i have an unsigned integer that contain 4 ASCII code for a string: 0x41424344--------- my unsigned integer I would like to print the out "ABCD" where th...
Altera_Forum
Honored Contributor
15 years agoIt is generally safer to use arithmetic to get the byte values from an integer.
So something like:void print_val(unsigned int val)
{
unsigned char c;
c = val;
c = val >>= 8;
c = val >>= 8;
c = val >> 8;
printf("%c%c%c%c", c, c, c, c);
}