How to print hex value of 255 in Unix?
can 开发者_运维问答you please tell me
How to use printf to find out the hex and octal values of 255?
Thanks a lot.
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
$
Try this:
printf("%x", 255); /* print hex representation of decimal 255 */
printf("%o", 255); /* print octal representation of decimal 255 */
精彩评论