Fortran: printing the Printing the Hex contents of a character variable

  1. Given a character variable

    character*10 name

    write (6,111) name

    111 format (?)

    what do I put in the format statement to print the hexadecimal contents of name?
  2. jcsd
  3. Hhhmmm...I have never had such need. I don't think there is such a shortcut in Fortran as there is in C; so, I am afraid you are going to have to write your own little function to do so.

    First, you will have to convert the character to decimal; you can use ichar(letter) for that. But then, you need your own little recursive function to produce hex. Here is a simple explanation of how to go about it for any decimal.
Know someone interested in this topic? Share this thead via email, Google+, Twitter, or Facebook

Have something to add?