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

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

Leigh_Wardle1
Beginner
378 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
Black Belt
327 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

2 Replies
mecej4
Black Belt
328 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.

Leigh_Wardle1
Beginner
319 Views

Thanks for your help, mecej4.

ICHAR works!

Regards,

Leigh

Reply