2

I want to convert a decimal number to hexadecimal number. I used the command :

printf '%X\n' 053698180

This command is working perfectly fine on Linux server. But throwing the below error when tried on UNIX :

printf: Error converting 053698180
053698180

What could be the issue here?

Also, what is the least possible correction that can be made here so as to make it work on UNIX and Linux both?

  • Actually, it is not working perfectly fine. You are using the Z shell and you have the octalzeroes option turned off. The Bourne Again shell, the Debian Almquist shell, the Korn shell, and the external printf command on your Linux system will all print error messages with these arguments, as indeed will the Z shell with the octalzeroes option turned on. – JdeBP Dec 9 '16 at 18:32
4

You didn't tell us what is your Unix and your shell. The problem lies probably in the leading 0 which instructs printf to interpret the number as an octal number, which it can't be (due to the 8 and 9 digits).

Just remove the leading 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.