Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Mar 30, 2012 #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. Apr 1, 2012 #2
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook