[UP]


Manual Reference Pages  - base (3)

NAME

base(3f) - [M_strings:BASE] convert whole number string in base [2-36] to string in alternate base [2-36] (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Example
Author
License

SYNOPSIS

logical function base(x,b,y,a)

character(len=*),intent(in) :: x character(len=*),intent(out) :: y integer,intent(in) :: b,a

DESCRIPTION

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.

OPTIONS

x input string representing numeric whole value
b assumed base of input string
y output string
a base specified for output string

EXAMPLE

Sample program:

   program demo_base
   use M_strings, only : base
   implicit none
   integer           :: ba,bd
   character(len=40) :: x,y

print *,’ 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

AUTHOR

John S. Urban

LICENSE

Public Domain


base (3) July 05, 2020
Generated by manServer 1.08 from 27957b5a-74f0-4163-b065-66b0331d2ebb using man macros.