Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28383 Discussions

How to convert one character to a variable that is type integer(BYTE)

Leigh_Wardle1
Beginner
786 Views

Hi all,

I need a Fortran code that will give me the MD5 hash of a string.
The nearest thing to a solution is code from https://rosettacode.org/wiki/MD5

It appears to process a bunch of files defined via command-line arguments.

I have tried running it with one file, but it throws an unhandled exception.

I have stripped out the file processing, but I am stuck with this type conversion issue.

Here is a fragment of the code:

integer(BYTE) :: buffer(BUFLEN)
character*(*) chrStringToBeHashed
Integer intlenStringToBeHashed
Integer j

intlenStringToBeHashed = LEN(chrStringToBeHashed)
do j = 1, intlenStringToBeHashed

! here I am trying to convert one character to buffer(j), which is type integer(BYTE)
buffer(j) = chrStringToBeHashed(j:j)
end do

The issue is how do I convert one character to a variable that is type integer(BYTE)?

I have attached my Project.

 

Regards,
Leigh

0 Kudos
1 Solution
mecej4
Honored Contributor III
735 Views

"how do I convert one character to a variable that is type integer(BYTE)?"

The intrinsic function ICHAR will do that. Please look up the description of that function in the Fortran documentation.

View solution in original post

0 Kudos
2 Replies
mecej4
Honored Contributor III
736 Views

"how do I convert one character to a variable that is type integer(BYTE)?"

The intrinsic function ICHAR will do that. Please look up the description of that function in the Fortran documentation.

0 Kudos
Leigh_Wardle1
Beginner
727 Views

Thanks for your help, mecej4.

ICHAR works!

Regards,

Leigh

0 Kudos
Reply