- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I had assumed that at least looking up a certain bit (i.e. base-2) of a given integer would be easily available but I cannot find this even in IMSL.
Thanks,
Tim
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Steve
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
module Base
integer(1),parameter:: maxBins=31
integer(4),parameter:: maxVal=2**maxBins-1
contains
!==================================================
!Converts inVal from decimal to base N (int-1)
! returns an array of size maxBins with the bit values
! on error sets the returned array to zero.
function D2Base(inVal, N) result (str)
implicit none
integer(1):: str(maxBins)
integer(4), intent(in):: inVal
integer(1), intent(in):: N
integer(4)::M
integer(1)::i
str=0
if(N<=0 .or. N>9 .or. inVal<=0 .or. inVal>maxVal)return
M=inVal
i=1
do while(M>=N)
str(i)=Mod(M,N)
M=M/N
i=i+1
enddo
str(i)=M
end function D2Base
!======================================================
integer(4) function Base2D(str, N) result (dec)
integer(1), intent(in):: str(maxBins),N
integer(1)::i
dec=0
do i=1,maxBins
!if(str(i)>=N)then; dec=0; return; endif
if(str(i)==0)cycle
dec=dec+str(i)*N**(i-1)
enddo
end function Base2D
!===================================================
end module Base
!=======================================================
use base
integer(1):: str(maxBins),b=8
m=23434
str=D2Base(M, b)
write(*,'(
write(*,*)Base2D(str, b)
pause
end
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable