A
alcastle
I'm new to C. I have a snippet of code that works, but it's a little
off in the output. I'm hoping someone can spot my error(s).
I'm reading input from a serial device, and I need to print Hex, which
is working but I'm getting unreliable output and have formating issues.
Example output:
FF00000033 FF00000036 FF00000030 FF00000030 FF00000054 FF0000001A
FF0000000F FF00000048 FF00000003 FF0000004A FF00000020 FF00000003
FF00000000 FF00000021 FF00000000 FF00000026 FF00000022 FF00000075
FF00000000 FF00000023 FF00000011 FF00000040 FF00000024 FF0000007F
FF00000040 FF00000025 FF0000000F FF00000050 FF00000026 FF0000007F
FF00000040 FF00000027 FF0000007F FF00000040 FF00000023
I can't figure out how to get rid of the FF000000 before the actual
HEX. And in about half of these the hex translation is wrong. Example:
the second to last frame on the last line; 40 should be C0.
I've tried various printf output options, but they all spit out
unreliable output with formating issues. I must be skipping a step, or
I need to multiply by something?
I've gone through the binary to hex posts and have tried some of the
things suggested but it's either over my head at this point or just
isn't working.
<snippet>
int res;
char buf[255];
retval = select(fd+1, &set, NULL,NULL, &timeout);
if (retval > 0) {
res = read(fd,buf,255);
if (res <= 0) {
printf("Error, res is <= 0");
}
int i;
buf[res]=0;
for (i=0;i<res;i++) {
printf("%0LX ", (int)(buf)); //mostly
}
</snippet>
Any suggestions would be greatly appreciated.
off in the output. I'm hoping someone can spot my error(s).
I'm reading input from a serial device, and I need to print Hex, which
is working but I'm getting unreliable output and have formating issues.
Example output:
FF00000033 FF00000036 FF00000030 FF00000030 FF00000054 FF0000001A
FF0000000F FF00000048 FF00000003 FF0000004A FF00000020 FF00000003
FF00000000 FF00000021 FF00000000 FF00000026 FF00000022 FF00000075
FF00000000 FF00000023 FF00000011 FF00000040 FF00000024 FF0000007F
FF00000040 FF00000025 FF0000000F FF00000050 FF00000026 FF0000007F
FF00000040 FF00000027 FF0000007F FF00000040 FF00000023
I can't figure out how to get rid of the FF000000 before the actual
HEX. And in about half of these the hex translation is wrong. Example:
the second to last frame on the last line; 40 should be C0.
I've tried various printf output options, but they all spit out
unreliable output with formating issues. I must be skipping a step, or
I need to multiply by something?
I've gone through the binary to hex posts and have tried some of the
things suggested but it's either over my head at this point or just
isn't working.
<snippet>
int res;
char buf[255];
retval = select(fd+1, &set, NULL,NULL, &timeout);
if (retval > 0) {
res = read(fd,buf,255);
if (res <= 0) {
printf("Error, res is <= 0");
}
int i;
buf[res]=0;
for (i=0;i<res;i++) {
printf("%0LX ", (int)(buf)); //mostly
}
</snippet>
Any suggestions would be greatly appreciated.