base(3f) - [M_strings:BASE] convert whole number string in base [2-36] to string in alternate base [2-36] (LICENSE:PD)
Synopsis
Description
Options
Example
Author
License
logical function base(x,b,y,a)character(len=*),intent(in) :: x character(len=*),intent(out) :: y integer,intent(in) :: b,a
Convert a numeric string from base B to base A. The function returns FALSE if B is not in the range [2..36] or if string X contains invalid characters in base B or if result Y is too big
The letters A,B,...,Z represent 10,11,...,36 in the base > 10.
x input string representing numeric whole value b assumed base of input string y output string a base specified for output string
Sample program:
program demo_base use M_strings, only : base implicit none integer :: ba,bd character(len=40) :: x,yprint *, BASE CONVERSION write(*,("Start Base (2 to 36): "),advance=no); read *, bd write(*,("Arrival Base (2 to 36): "),advance=no); read *, ba INFINITE: do write(*,("Enter number in start base: "),advance=no); read *, x if(x.eq.0) exit INFINITE if(base(x,bd,y,ba))then write(*,("In base ",I2,": ",A20)) ba, y else print *,Error in decoding/encoding number. endif enddo INFINITE
end program demo_base
John S. Urban
Public Domain
base (3) | July 05, 2020 |