Re: How to print out



Keith Thompson <kst-u@xxxxxxx> writes:

"Praetorian" <ashish.sadanandan@xxxxxxxxx> writes:
poison.summer@xxxxxxxxx wrote:
what if I want it in hex mode?
I did the same thing, but when I use %x, it doesn't work

thanks again

So the printing as ints worked but hex didn't? I have no idea why this
would happen, you can try cast the result of each masking operation as
an int once again but I doubt this will fix it.

Sorry, but "try a cast, but I doubt that it will fix it" is bad advice.

All casts should be viewed with suspicion. A cast is often used to
tell the compiler, "I know what I'm doing; don't bother me with
warnings"; if you *don't* know what you're doing, you're very likely
to shoot yourself in the foot. (The classic example is casting the
result of malloc() to disable a warning caused by a missing
"#include <stdlib.h".)

We need to see the OP's actual code before we can offer any advice;
trying to guess what "it doesn't work" really means won't do any good.
(If the OP doesn't come back and tell us what he meant, we can assume
he didn't really need or want any help.)

We're missing some context. The message to which poison.summer was
responding, written by Praetorian, had:

printf("Lower = %d, Upper = %d",(int)p&0xF,((int)p&0xF0)>>4);

In this case, if %d is changed to %x, casting (or rather, /changing/
the existing casts to (unsigned int)) seems appropriate (if perhaps
unnecessary, depending on the type of p).

However, telling us "it doesn't work" is not informative. Please post
a smallish amount of code that will compile (has a main() function,
etc.) that illustrates the problem, along with the output you are
getting from it.

-Micah
.


Quantcast