How to print hex value of 255 in Unix? How to print hex value of 255 in Unix? unix unix

How to print hex value of 255 in Unix?


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" 255377$ printf "%x\n" 255ff$ 


Try this:

printf("%x", 255);  /* print hex representation of decimal 255 */printf("%o", 255);  /* print octal representation of decimal 255 */