View previous topic :: View next topic |
Author |
Message |
m.burkhardt
Joined: 02 Sep 2008 Posts: 26
|
Posted: Mon Jan 17, 2011 9:49 am Post subject: ERROR in Fortran Code(cannot be in logical expressions) |
|
|
Hello, I have a question: In an Fortran code (Visual Studio) I have the following expression:
INTEGER*2 KENN
INTEGER*2 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 |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Jan 17, 2011 10:17 am Post subject: |
|
|
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). |
|
Back to top |
|
 |
m.burkhardt
Joined: 02 Sep 2008 Posts: 26
|
Posted: Tue Jan 18, 2011 9:45 am Post subject: ERROR in Fortran Code(cannot be in logical expressions) |
|
|
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 |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Tue Jan 18, 2011 12:59 pm Post subject: |
|
|
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:
Code: | program cutandpaste
integer :: i
character(len=4) hex
do i=0,10000
WRITE(hex,'(Z4.0)') i
write(*,'(A4)') hex
enddo
end |
|
|
Back to top |
|
 |
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Tue Jan 18, 2011 2:55 pm Post subject: |
|
|
Quote: | 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.
Quote: | 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:
Code: | KENN = IAND(R5, Z'FF00') |
|
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Wed Jan 19, 2011 3:22 pm Post subject: |
|
|
As the functions are now generic, AND (...) would do as well as IAND (...)
E |
|
Back to top |
|
 |
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Wed Jan 19, 2011 4:15 pm Post subject: |
|
|
Yes, AND() should work but not .AND. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Jan 25, 2011 11:56 pm Post subject: Re: |
|
|
LitusSaxonicum wrote: | 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.
Code: |
KENN = IAND(R5, 255)
|
|
|
Back to top |
|
 |
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Wed Jan 26, 2011 8:25 am Post subject: |
|
|
Quote: | Try the following to extract the low byte. |
He wants to extract the high byte, see my posting+code. |
|
Back to top |
|
 |
|