Posts

Showing posts with the label integer

Convert an array of logical type to an array of integer/double type

Convert an array of logical type to an array of integer/double type I am using Silverfrost FTN95 and, since I am not an expert, I need your help to create a function which takes as input an array of logical variables and returns an array of integer variables, 0 for false and 1 for true. I wrote this simple code just to semplify how I tried to implement it: program main logical, dimension(2,1) :: a integer, dimension(2,1) :: b integer, dimension(2,1) :: toInt a(:,1)=.false. b=toInt(a) write(*,*)b end program function toInt(log) result(val) logical, dimension(2,1), intent(in) :: log integer, dimension(2,1) :: val do i=1,2 if (log(i,1)) then val(i,1) = 1 else val(i,1) = 0 end if end do end function This code gives me this error: INTEGER expression expected in array bounds subscript, variable 'A' does not have the INTEGER type (at line "b=toInt(a)"), and I can't find what the error is. Any suggestions or othe...

Using java to encrypt integers

Using java to encrypt integers I'm trying to encrypt some integers in java using java.security and javax.crypto. The problem seems to be that the Cipher class only encrypts byte arrays. I can't directly convert an integer to a byte string (or can I?). What is the best way to do this? Should I convert the integer to a string and the string to byte? This seems too inefficient. Does anyone know a quick/easy or efficient way to do it? Please let me know. Thanks in advance. jbu Hmm.. are you going between different Endianness? If so that would cause those integers to be incorrect when you converted them back from the byte array.. – SCdF Nov 26 '08 at 19:19 Apparerntly "Java virtual machine always used big-endian", so I guess it's not an issue. – SCdF No...