Silverfrost Forums

Welcome to our forums

ERROR in Fortran Code(cannot be in logical expressions)

17 Jan 2011 8:49 #7511

Hello, I have a question: In an Fortran code (Visual Studio) I have the following expression: INTEGER2 KENN INTEGER2 R5 ... KENN = R5 .AND. 'HFF00'

after this expression, I get the following error: 'INTEGER(KIND=2) variables, such as R5, cannot be in logical expressions (with '.AND.').' 😦

What is my Problem? :?:

Greetings from Germany! Michael

17 Jan 2011 9:17 #7512

It seems like a logical expression from the compiler 😃

Spaß bei Seite: What would you like to do? You have a string and an integer in your expression - the result must be an integer (KENN).

18 Jan 2011 8:45 #7525

Thank you for helping me! 😄 I want to extract the low byte. A logical AND bit operation if R5 has the Value in Hex '014F' after the operation KENN is Hex '0100'. Thats what the expression do in the past.

Greetings an thanks! Michael

18 Jan 2011 11:59 #7531

I am not familiar with hexadecimal in Fortran and a quick search did not deliver any positive results. An attempt would be to write a little subroutine that uses strings. Here you have an internal write to convert from integer to string:

program cutandpaste

integer :: i
character(len=4) hex

do i=0,10000
  WRITE(hex,'(Z4.0)') i
  write(*,'(A4)') hex
enddo
end
18 Jan 2011 1:55 #7535

I want to extract the low byte. A logical AND bit operation

.AND. is no bit operation, it's a boolean operation (both operands logical values) so I don't have a clue how the code you posted would ever have extracted bits.

I want to extract the low byte. if R5 has the Value in Hex '014F' after the operation KENN is Hex '0100'.

If you extract the low byte of 0x014F you'll get 0x004F, so I assume you want to mask out the low byte. This can be done with for example the following code:

KENN = IAND(R5, Z'FF00')
19 Jan 2011 2:22 #7549

As the functions are now generic, AND (...) would do as well as IAND (...)

E

19 Jan 2011 3:15 #7553

Yes, AND() should work but not .AND.

25 Jan 2011 10:56 #7625

Quoted from LitusSaxonicum As the functions are now generic, AND (...) would do as well as IAND (...)

Are you sure?

I don't think there is an AND intrinsic function (unless new in 2003/08)! I always use IAND, IOR etc. when using bitwise operations. Don't these only work with integers (of various KINDs) so don't need to be generic (overloaded)?

Try the following to extract the low byte.

KENN = IAND(R5, 255)
26 Jan 2011 7:25 #7627

Try the following to extract the low byte.

He wants to extract the high byte, see my posting+code.

Please login to reply.