views:

88

answers:

2

Hi, can you please tell me

How to use printf to find out the hex and octal values of 255?

Thanks a lot.

+1  A: 

Try this:

printf("%x", 255);  /* print hex representation of decimal 255 */
printf("%o", 255);  /* print octal representation of decimal 255 */
Daren Thomas
Thanks a lot, printf "%o" 255 and printf "%x" 255 works as you mentioned.
you're welcome.
Daren Thomas
+6  A: 

Try using the o and x specifier of printf

printf("%d %o %x",255,255,255); // prints 255 377 ff

If you want to do this on shell you can do:

$ printf "%o\n" 255
377
$ printf "%x\n" 255
ff
$ 
codaddict
+1 for pointing out that this can be done in shell too! I just kinda guessed he meant C (because, well, the OP mentioned UNIX, duh!)
Daren Thomas