These files have been made freely available by SGS-Thomson and may not be used to generate commercial products without explicit permission and agreed licensing terms OR placed in a public archive or given to third parties without explicit written permission from SGS-Thomson in Bristol.

Tony Debling, SGS-Thomson Microelectronics Ltd, 1000 Aztec West, Almondsbury, Bristol BS12 4SQ, England. June 7, 1995.

Converted to HTML via RTFtoHTML, PERL5 and by hand by Dave Beckett <D.J.Beckett@ukc.ac.uk>.

WARNING: This has been converted from RTF format and may have mistakes compared to the printed version. If you find any in this file, please send them to me, and I will update it.

Dave Beckett <D.J.Beckett@ukc.ac.uk>

These routines are also described in appendix O of the *occam 2 Reference
Manual*.

Procedure Parameter Specifiers INTTOSTRING INT len, []BYTE string, VAL INT n INT16TOSTRING INT len, []BYTE string, VAL INT16 n INT32TOSTRING INT len, []BYTE string, VAL INT32 n INT64TOSTRING INT len, []BYTE string, VAL INT64 n HEXTOSTRING INT len, []BYTE string, VAL INT n HEX16TOSTRING INT len, []BYTE string, VAL INT16 n HEX32TOSTRING INT len, []BYTE string, VAL INT32 n HEX64TOSTRING INT len, []BYTE string, VAL INT64 n REAL32TOSTRING INT len, []BYTE string, VAL REAL32 X, VAL INT Ip, Dp REAL64TOSTRING INT len, []BYTE string, VAL REAL64 X, VAL INT Ip, Dp BOOLTOSTRING INT len, []BYTE string, VAL BOOL b STRINGTOINT BOOL Error, INT n, VAL []BYTE string STRINGTOINT16 BOOL Error, INT16 n, VAL []BYTE string STRINGTOINT32 BOOL Error, INT32 n, VAL []BYTE string STRINGTOINT64 BOOL Error, INT64 n, VAL []BYTE string STRINGTOHEX BOOL Error, INT n, VAL []BYTE string STRINGTOHEX16 BOOL Error, INT16 n, VAL []BYTE string STRINGTOHEX32 BOOL Error, INT32 n, VAL []BYTE string STRINGTOHEX64 BOOL Error, INT64 n, VAL []BYTE string STRINGTOREAL32 BOOL Error, REAL32 X, VAL []BYTE string STRINGTOREAL64 BOOL Error, REAL64 X, VAL []BYTE string STRINGTOBOOL BOOL Error, b, VAL []BYTE string

PROC INTTOSTRING (INT len, []BYTE string,

VAL INT n)

Converts an integer value to a string. The procedure returns the decimal representation ofinnand the number of characters in the representation, instring. Iflenis not long enough to hold the representation then this routine acts as an invalid process.stringSimilar procedures are provided for the types

,INT16, andINT32.INT64

**INT16TOSTRING**** **

PROC INT16TOSTRING (INT len, []BYTE string,

VAL INT16 n)

Asbut for 16-bit integers.INTTOSTRING

**INT32TOSTRING**** **

PROC INT32TOSTRING (INT len, []BYTE string,

VAL INT32 n)

Asbut for 32-bit integers.INTTOSTRING

**INT64TOSTRING**** **

PROC INT64TOSTRING (INT len, []BYTE string,

VAL INT64 n)

Asbut for 64-bit integers.INTTOSTRING

**HEXTOSTRING**** **

PROC HEXTOSTRING (INT len, []BYTE string,

VAL INT n)

The procedure returns the hexadecimal representation ofinnstringand the number of characters in the representation, in. All the bits oflen, (in 4-bit wide word lengths) are output so that leading zeroes or `F's are included. The number of characters will be the number of bits in anndivided by four. A `INT' is not output by the#procedure. IfHEXTOSTRINGis not long enough to hold the representation then this routine acts as an invalid process.stringSimilar procedures are provided for the types

,HEX16andHEX32.HEX64

**HEX16TOSTRING**** **

PROC HEX16TOSTRING (INT len, []BYTE string,

VAL INT16 n)

Asbut for 16-bit integers.HEXTOSTRING

**HEX32TOSTRING**** **

PROC HEX32TOSTRING (INT len, []BYTE string,

VAL INT32 n)

Asbut for 32-bit integers.HEXTOSTRING

**HEX64TOSTRING**** **

PROC HEX64TOSTRING (INT len, []BYTE string,

VAL INT64 n)

Asbut for 64-bit integers.HEXTOSTRING

**REAL32TOSTRING**** **

PROC REAL32TOSTRING (INT len, []BYTE string,

VAL REAL32 X,

VAL INT Ip, Dp)

Converts a 32-bit real number (represented in single precision IEEE format) to a string of ASCII characters.is the number of characters (lens) of string used for the formatted decimal representation of the number. (The following description applies to and notes the differences between this procedure andBYTE).REAL64TOSTRINGThe string must match the format for occam real literals as defined in the

occam 2 Reference Manual, p 123, for example,.1.2E+2Depending on the value of

and the two formatting variablesXandIpDpthe procedure will use either a fixed or exponential format for the output string. These formats are defined as follows:

Fixed : First, either a minus sign or space (an explicit plus sign is not used), followed by a fraction in the form <digits>.<digits>. Padding spaces are added to the left of the sign indicator, as necessary. (Ip gives the number of places before the point and Dp the number of places after the point). Exponential : First, either a minus sign or space (again, an explicit plus sign is not used), followed by a fraction in the form <digit>.<digits>, the exponential symbol (E), the sign of the exponent (explicitly plus or minus), then the exponent, which is two digits for a REAL32 and three digits for a REAL64. (Dp gives the number of digits in the fraction (1 before the decimal point and the others after)).

Possible combinations ofandIpfall into three categories, described below.DpNote: the term `Free format' means that the procedure may adopt either fixed or exponential format, depending on the actual value of.X

- If
=0,**Ip**=0, then free format is adopted. Exponential format is used if the absolute value of**Dp**is less than 10^(**X***-*4), but non-zero, or greater than 10^(9) (for), or greater than 10^(17) (for**REAL32**); otherwise fixed format is used.**REAL64**

The value ofis dependent on the actual value oflenwith trailing zeroes suppressed. The maximum length of the result is 15 or 24, depending on whether it isXorREAL32respectively.REAL64If

is `Not-a-Number' or infinity then the string will contain one of the following: `X', `Inf-' or `Inf', (excluding the quotes).NaN

- If
>0,**Ip**>0, fixed format is used, unless the value needs more than**Dp**significant digits before the decimal point, in which case, exponential format is used. If exponential does not fit either, then a signed string `**Ip**' is produced. The length is always**Ov**+**Ip**+ 2 when**Dp**>0,**Ip**>0.**Dp**

Ifis `Not-a-Number' or infinity then the string will contain one of the following: `X', `Inf-' or `Inf', (excluding the quotes) and padded out by spaces on the right to fill the field width.NaN

- If
=0,**Ip**>0, then exponential format is always used. The length of the result is**Dp**+ 6 or**Dp**+ 7, depending on whether**Dp**is a**X**or**REAL32**, respectively.**REAL64**

If=0,Ip=1, then a special result is produced consisting of a sign, a blank, a digit and the exponent. The length is 7 or 8 depending on whetherDpis aXorREAL32.REAL64Note: this result does not conform to the occam format for a.REALIf

is `Not-a-Number' or infinity then the string will contain one of the following: `X', `Inf-' or `Inf', (excluding the quotes) and padded out by spaces on the right to fill the field width.NaN

All other combinations ofandIpare errors.DpIf string is not long enough to hold the requested formatted real number as a string then these routines act as invalid processes.

**REAL64TOSTRING**** **

PROC REAL64TOSTRING (INT len, []BYTE string,

VAL REAL64 X,

VAL INT Ip, Dp)

Asbut for 64-bit numbers.REAL32TOSTRING

**BOOLTOSTRING**** **

PROC BOOLTOSTRING (INT len, []BYTE string,

VAL BOOL b)

Converts a boolean value to a string. The procedure returns `' inTRUEifstringisband `TRUE' otherwise.FALSEcontains the number of characters in the string returned. Iflenis not long enough to hold the representation then this routine acts as an invalid process.string

**STRINGTOINT**** **

PROC STRINGTOINT (BOOL Error, INT n,

VAL []BYTE string)

Converts a string to a decimal integer. The procedure returns inthe value represented inn.stringis set toerrorif a non-numeric character is found inTRUEor ifstringis empty. + or a - are allowed in the first character position.stringwill be the value of the portion ofnup to any illegal characters, with the convention that the value of an empty string is 0.stringis also set toerrorif the value ofTRUEoverflows the range ofstring, in this caseINTwill contain the low order bits of the binary representation ofn.stringis set toerrorin all other cases.FALSESimilar procedures are provided for the types

,INT16, andINT32.INT64

**STRINGTOINT16**** **

PROC STRINGTOINT16 (BOOL Error, INT16 n,

VAL []BYTE string)

Asbut converts to a 16-bit integer.STRINGTOINT

**STRINGTOINT32**** **

PROC STRINGTOINT32 (BOOL Error, INT32 n,

VAL []BYTE string)

Asbut converts to a 32-bit integer.STRINGTOINT

**STRINGTOINT64**** **

PROC STRINGTOINT64 (BOOL Error, INT64 n,

VAL []BYTE string)

Asbut converts to a 64-bit integer.STRINGTOINT

**STRINGTOHEX**** **

PROC STRINGTOHEX (BOOL Error, INT n,

VAL []BYTE string)

The procedure returns inthe value represented by the hexadecimaln. No `string' is allowed in the input and hex digits must be in upper case (#toA) rather than lower case (Ftoa).fis set toerrorif a non-hexadecimal character is found inTRUE, or ifstringstringis empty.will be the value of the portion ofnup to any illegal character with the convention that the value of an empty string isstring.0is also set toerrorif the value represented byTRUEoverflows the range ofstring. In this caseINTwill contain the low order bits of the binary representation ofn. In all other casesstringis set toerror.FALSESimilar procedures are provided for the types

,HEX16, andHEX32.HEX64

**STRINGTOHEX16**** **

PROC STRINGTOHEX16 (BOOL Error, INT16 n,

VAL []BYTE string)

Asbut converts to a 16-bit integer.STRINGTOHEX

**STRINGTOHEX32**** **

PROC STRINGTOHEX32 (BOOL Error, INT32 n,

VAL []BYTE string)

Asbut converts to a 32-bit integer.STRINGTOHEX

**STRINGTOHEX64**** **

PROC STRINGTOHEX64 (BOOL Error, INT64 n,

VAL []BYTE string)

Asbut converts to a 64-bit integer.STRINGTOHEX

**STRINGTOREAL32**`
`

PROC STRINGTOREAL32 (BOOL Error, REAL32 X,

VAL []BYTE string)

Converts a string to a 32-bit real number. This procedure takes a string containing a decimal representation of a real number and converts it into the corresponding real value. If the value represented byoverflows the range of the type then an appropriately signed infinity is returned. Errors in the syntax of string are signalled by a `Not-a-Number' being returned andstringbeing set toerror. The string is scanned from the left as far as possible while the syntax is still valid. If there are any characters after the end of the longest correct string thenTRUEis set toerror, otherwise it isTRUE. For example ifFALSEwas ``12.34stringE+2+1.0'' then the value returned would be 12.34 10^(2)with^(error)set to^()TRUE^(.)

**STRINGTOREAL64**** **

PROC STRINGTOREAL64 (BOOL Error, REAL64 X,

VAL []BYTE string)

Asbut converts to a 64-bit number.STRINGTOREAL32

**STRINGTOBOOL**** **

PROC STRINGTOBOOL (BOOL Error, b,

VAL []BYTE string)

Converts a string to a boolean value. The procedure returnsinTRUEif the first four characters ofbare `string' andTRUEif the first five characters are `FALSE';FALSEis undefined in other cases.bis returned inTRUEiferroris not exactly `string' or `TRUE'.FALSE