GerritGroot
Technical User
Hi,
I've got a question about the transfer function. I'd like to transfer a two byte integer to a four byte integer using
The above integers are declared as:
The two byte integer is read correctly from a binary file
opened as:
and has the value -99. However, when I use the above transfer statement: FourByteInt=4390813
"Maybe something with the sign bit," I thought at first and then I tried to change the sign in TwoByteInt from -99 to 99 and use the transfer function afterwards, but this gives: FourByteInt=4325475. (If I'd have to take the sign into account the transfer function wouldn't be useful anyway, so I suppose the transfer function works for negative values as well)
The binary file has been written on windows by a commercial code, so I suppose it's all little-endian, I'm working on XP myself and the value -99 is read correctly.
What am I doing wrong? How do I get FourByteInt=-99??
Thanks,
Gerrit
I've got a question about the transfer function. I'd like to transfer a two byte integer to a four byte integer using
Code:
FourByteInt=TRANSFER(TwoByteInt,FourByteInt)
The above integers are declared as:
Code:
INTEGER, PARAMETER :: I2B=SELECTED_INT_KIND(4)
INTEGER, PARAMETER :: I4B=SELECTED_INT_KIND(9)
INTEGER(KIND=I2B) :: TwoByteInt
INTEGER(KIND=I4B) :: FourByteInt
The two byte integer is read correctly from a binary file
opened as:
Code:
OPEN(UNIT=1,FILE='./INPUT/MyBinary.bin',ACCESS='DIRECT',FORM='BINARY',RECL=2,STATUS='OLD')
READ(1,REC=1)TwoByteInt
"Maybe something with the sign bit," I thought at first and then I tried to change the sign in TwoByteInt from -99 to 99 and use the transfer function afterwards, but this gives: FourByteInt=4325475. (If I'd have to take the sign into account the transfer function wouldn't be useful anyway, so I suppose the transfer function works for negative values as well)
The binary file has been written on windows by a commercial code, so I suppose it's all little-endian, I'm working on XP myself and the value -99 is read correctly.
What am I doing wrong? How do I get FourByteInt=-99??
Thanks,
Gerrit