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

AI Thread Summary
To print the hexadecimal contents of a character variable in Fortran, a specific format statement is needed. There isn't a direct shortcut in Fortran like in C, necessitating the creation of a custom function. The process involves converting each character to its decimal equivalent using the ichar function. After obtaining the decimal value, a recursive function is required to convert these decimal values into hexadecimal format. This approach allows for the desired hexadecimal representation of the character variable.
physicsposter
Messages
1
Reaction score
0
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?
 
Technology news on Phys.org
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
9
Views
5K
Replies
25
Views
3K
Replies
13
Views
2K
Replies
12
Views
3K
Replies
19
Views
2K
Replies
5
Views
2K
Back
Top