## Conversion Utilities

The conversion utilities are:

%DO: Decimal to octal conversion.

%LCASE: Converts a string to all lower case.

%OD: Octal to decimal conversion.

%UCASE: Converts a string to all upper case.

The conversion utilities can be invoked as extrinsic functions.

The "%" sign has been removed from the topic headings below, intentionally.

### %DH

The %DH utility converts numeric values from decimal to hexadecimal. %DH defaults the length of its output to eight digits. However the input variable %DL overrides the default and controls the length of the output. The routine has entry points for interactive or non-interactive use.

#### Utility Labels

INT: Converts interactively entered decimal number to hexadecimal number with the number of digits specified.

FUNC(d[,l]): Invokes %DH as an extrinsic function returning the hexadecimal equivalent of the argument.

#### Input Variables

%DH: As input, contains input decimal number.

%DL: Specifies how many digits appear in the output, defaults to eight.

#### Prompts

Decimal: Requests a decimal number for conversion to hexadecimal.

Digits: Requests the length of the output in digits; eight by default.

#### Output Variables

%DH: As output, contains the converted number in hexadecimal.

#### Examples of %DH

Example:

```GTM>DO INT^%DH
Decimal: 12
Digits: 1
GTM>ZWRITE
%DH="C" ```

This example invokes %DH interactively with INT^%DH. %DH prompts for a decimal number and output length, then returns the result in the variable %DH. ZWRITE displays the contents of the variables.

Example:

```GTM>SET %DH=12
GTM>DO ^%DH
GTM>ZWRITE
%DH="0000000C"
%DL=8 ```

This example sets the read-write variable %DH to 12 and invokes %DH to convert the number to a hexadecimal number. Because the number of digits was not specified, %DH used the default of 8 digits. Set %DL to specify the number of output digits.

Example:

```GTM>WRITE \$\$FUNC^%DH(12,4)
000C```

This example invokes %DH as an extrinsic function using the FUNC label. The first argument specifies the input decimal number and the optional, second argument specifies the number of output digits. If the extrinsic does not have a second argument, the length of the output defaults to eight characters.

### %DO

The %DO utility converts numeric values from decimal to octal. The default length of its output is 12 digits. The value assigned to the input variable %DL overrides the default and controls the length of the output. The routine has entry points for interactive or non-interactive use.

#### Utility Labels

INT: Converts the specified decimal number to an octal number with the specified number of digits, interactively.

FUNC(d[,ln]): Invokes %DO as an extrinsic function, returning the octal equivalent of the argument.

#### Prompts

Decimal: Requests a decimal number for conversion to octal.

Digits: Requests the length of the output in digits; 12 by default.

#### Input Variables

%DO: As input, contains input decimal number.

%DL: Specifies the number of digits in the output, defaults to 12.

#### Output Variables

%DO: As output, contains the converted number in octal.

#### Examples of %DO

Example:

```GTM>DO INT^%DO
Decimal: 12
Digits: 4
GTM>ZWRITE
%DO="0014"```

This example invokes %DO interactively with INT^%DO. %DO prompts for a decimal number and an output length. If the output value of %DO has leading zeros, the value is a string. ZWRITE displays the contents of the variables.

Example:

```GTM>SET %DO=12
GTM>DO ^%DO
GTM>ZWRITE
%DO="000000000014"```

This example sets the read-write variable %DO to 12 and invokes %DO to convert the number non-interactively. Because the number of digits was not specified, %DO used the default of 12 digits. Set %DL to specify the number of output digits. ZWRITE displays the contents of the variables.

Example:

```GTM>WRITE \$\$FUNC^%DO(12,7)
0000014 ```

This example invokes %DO as an extrinsic function with the label FUNC. The first argument specifies the number to be converted and the optional, second argument specifies the number of output digits. If the second argument is not specified, %DO uses the default of 12 digits.

### %HD

The %HD utility converts numeric values from hexadecimal to decimal. %HD returns the decimal number in the read-write variable %HD. %HD rejects input numbers beginning with a minus (-) sign and returns null (""). The routine has entry points for interactive or non-interactive use.

#### Utility Labels

INT: Converts hexadecimal number entered interactively to decimal number.

FUNC(h): Invokes %HD as an extrinsic function returning the decimal equivalent of the argument.

#### Input Variables

%HD: As input, contains input hexadecimal number.

#### Output Variables

%HD: As output, contains the converted number in decimal.

#### Examples of %HD

Example:

```GTM>DO INT^%HD
GTM>ZWRITE
%HD=14```

This example invokes %HD in interactive mode with INT^%HD. %HD prompts for a hexadecimal number, then returns the converted number in the variable %HD. ZWRITE displays the contents of the variable.

Example:

```GTM>SET %HD="E"
GTM>DO ^%HD
GTM>ZWRITE
%HD=14```

This example sets the read-write variable %HD to "E" and invokes %HD to convert non-interactively the value of %HD to a decimal number. %HD places the converted value into the read-write variable %HD.

Example:

```GTM>WRITE \$\$FUNC^%HD("E")
14```

This example invokes %HD as an extrinsic function with the label FUNC and writes the results.

### %HO

The %HO utility converts numeric values from hexadecimal to octal. %HO returns the octal number in the read-write variable %HO. %HO rejects input numbers beginning with a minus (-) sign and returns null (""). The routine has entry points for interactive or non-interactive use.

#### Utility Labels

INT: Converts hexadecimal number entered interactively to octal number.

FUNC(h): Invokes %HO as an extrinsic function returning the octal equivalent of the argument.

#### Input Variables

%HO: As input, contains input hexadecimal number.

#### Output Variables

%HO: As output, contains the converted number in octal.

#### Examples of %HO

Example:

```GTM>DO INT^%HO
GTM>ZWRITE
%HO=303```

This example invokes %HO in interactive mode using INT^%HO. %HO prompts for a hexadecimal number that it converts to an octal number. ZWRITE displays the contents of the variable.

Example:

```GTM>SET %HO="C3"
GTM>DO ^%HO
GTM>ZWRITE
%HO=303 ```

This example sets the read-write variable %HO to "C3" and invokes %HO to convert the value of %HO non-interactively. ZWRITE displays the contents of the variable.

Example:

```GTM>WRITE \$\$FUNC^%HO("C3")
303```

This example invokes %HO as an extrinsic function with the FUNC label.

### %LCASE

The %LCASE utility converts a string to all lower-case letters. If a routine uses this function repetitively, put the utility code directly into the M program.

#### Utility Labels

INT: Converts interactively a string to lower-case.

FUNC(s): Invokes %LCASE as an extrinsic function returning the lower-case form of the argument.

#### Prompts

String: Requests a string for conversion to lower case.

#### Input Variables

%S: As input, contains string to be converted to lower case.

#### Output Variables

%S: As output, contains the converted string in lower case.

#### Examples of %LCASE

Example:

```GTM>DO INT^%LCASE
String: LABEL
Lower: label```

This example invokes %LCASE in interactive mode using INT^%LCASE. %LCASE prompts for a string that it converts to all lower case.

Example:

```GTM>SET %S="Hello"
GTM>do ^%LCASE
GTM>zwrite
%S="hello" ```

This example sets the variable %S to the string "Hello" and invokes %LCASE non-interactively to convert the string.

Example:

```GTM>SET ^X="Hello"
GTM>WRITE \$\$FUNC^%LCASE(^X)
hello ```

This example sets the variable ^X to the string "Hello" and invokes %LCASE as an extrinsic function that returns "hello" in lower case.

### %OD

The %OD utility converts numeric values from octal to decimal. %OD returns the decimal number in the read-write variable %OD. %OD rejects input numbers beginning with a minus (-) sign and returns null (""). The routine has entry points for interactive or non-interactive use.

#### Utility Labels

INT: Converts octal number entered interactively to decimal number.

FUNC(oct): Invokes %OD as an extrinsic function returning the decimal equivalent of the argument.

#### Prompts

Octal: Requests an octal number for conversion to decimal.

#### Input Variables

%OD: As input, contains input octal number.

#### Output Variables

%OD: As output, contains the converted number in decimal.

#### Examples of %OD

Example:

```GTM>DO INT^%OD
Octal:14
GTM>ZWRITE
%OD=12```

This example invokes INT^%OD to interactively convert the octal number entered. %OD prompts for an octal number that it converts to a decimal. %OD returns the converted value in the variable %OD.

Example:

```GTM>SET %OD=14
GTM>DO ^%OD
GTM>ZWRITE
%OD=12```

This example sets the read-write variable %OD to 14 and invokes %OD to convert the number non-interactively. ZWRITE displays the contents of the variables.

Example:

```GTM>WRITE \$\$FUNC^%OD(14)
12```

This example invokes %OD as an extrinsic function with the FUNC label. The argument specifies the number to be converted.

### %OH

The %OH utility converts numeric values from octal to hexadecimal. %OH returns the hexadecimal number in the read-write variable %OH. %OH rejects input numbers beginning with a minus (-) sign. The routine has entry points for interactive or non-interactive use. In interactive mode, %OH rejects non-octal numbers with the following message, "Input must be an octal number". In non-interactive mode, %OH returns a null string ("") upon encountering a non-octal number.

#### Utility Labels

INT: Converts interactively octal number entered to hexadecimal number.

FUNC(oct): Invokes %OH as an extrinsic function returning the hexadecimal equivalent of the argument.

#### Prompts

Octal:Requests an octal number for conversion to hexadecimal.

#### Input Variables

%OH: As input, contains input octal number.

#### Output Variables

%OH: As output, contains the converted number in hexadecimal.

#### Examples of %OH

Example:

```GTM>DO INT^%OH
Octal:16
GTM>ZWRITE
%OH="E"```

This example invokes %OH in interactive mode using INT^%OH. %OH prompts for an octal number that it converts to a hexadecimal number. ZWRITE displays the contents of the variable.

Example:

```GTM>SET %OH=16
GTM>DO ^%OH
GTM>ZWRITE
%OH="E" ```

This example sets the read-write variable %OH to 16 and invokes %OH to convert the value of %OH non-interactively. ZWRITE displays the contents of the variable.

Example:

```GTM>WRITE \$\$FUNC^%OH(16)
E```

This example invokes %OH as an extrinsic function with the FUNC label.

### %UCASE

The %UCASE utility converts a string to all upper-case letters. If a routine uses this function repetitively, put the utility code directly into the M program.

#### Utility Labels

INT: Converts a string to upper case interactively.

FUNC(s): Invokes %UCASE as an extrinsic function, returning the upper-case form of the argument.

#### Prompts

String: Requests a string for conversion to upper case.

#### Input Variables

%S: As input, contains string to be converted to upper case.

#### Output Variables

%S: As output, contains the converted string in upper case.

#### Examples of %UCASE

Example:

```GTM>DO INT^%UCASE
String: test
Upper: TEST```

This example invokes %UCASE in interactive mode using INT^%UCASE. %UCASE prompts for a string that it converts to all upper case.

Example:

```GTM>SET ^X="hello"
GTM>WRITE \$\$FUNC^%UCASE(^X)
HELLO```

This example sets the variable X to the string "hello" and invokes %UCASE as an extrinsic function that returns "HELLO" in upper case.