MC Codes - Mask Character
Overview
The MC code includes a suffixed operator code that specifies one of the following processes:
-
Change characters to upper or lower case.
-
Extract a class of characters.
-
Replace characters.
-
Convert ASCII character codes to their hexadecimal or binary equivalents and vice versa.
-
Convert a hexadecimal value to its decimal or binary equivalent and vice versa.
-
Convert a decimal value to its equivalent in Roman numerals and vice versa.
MC codes retain delimiters within the string being converted, except for MCP and its variants which convert delimiters as described.
Codes
You should use the MC codes in attribute 8, except where the list below notes that input conversion is valid:
MC0 Extract only characters in standard alphabet.
MC1 Extract only characters in primary added alphabet.
MC2 Extract only characters in secondary added alphabet.
MCA Extract only characters in standard, primary added and secondary added alphabets.
MC/A Extract only non-alphabetic characters.
MCAB{S} Convert ASCII character codes to binary representation (suppress spaces).
MCAX Convert ASCII character codes to hexadecimal representation.
MCB Extract only alphabetic and numeric characters.
MC/B Extract only special characters that are neither alphabetic nor numeric.
MCBA Convert binary representation to ASCII characters.
MCBX Convert a binary value to its hexadecimal equivalent.
MCC;x;yChange all occurrences of character string x to character string y.
MCDR Convert a decimal value to its equivalent Roman numerals. This code's input conversion works effectively.
MCDX Convert a decimal value to its hexadecimal equivalent. This code's input conversion works effectively.
MCL Convert all upper case letters
MCN Extract only numeric characters
MC/N Extract only non-numeric characters.
MCNP{c} Convert paired hexadecimal digits preceded by a tilde or character c to ASCII code. This code inverts the conversion performed by the MCPN code.
MCP{c} Convert each non-printable character (X'00' to X'1F' and X'80' to X'FE') to a tilde (~) or to character c. If c is itself a tilde, all non-printable characters are removed.
MCPN{c} Convert each non-printable character (X'00' to X'1F' and X'80' to X'FE') to a tilde (~) or to character c, immediately followed by the two-character hexadecimal representation of the non-printable character. Any existing occurrences of character c are treated as if they are non-printable characters.
MCRD Convert Roman numerals to the decimal equivalent. This code's input conversion works effectively.
MCT Convert all upper case letters
MCU Convert all lower case letters
MCXA Convert hexadecimal representation to ASCII characters.
MCXB{S} Convert a hexadecimal value to its binary equivalent (suppress spaces).
MCXD Convert a hexadecimal value to its decimal equivalent. This code's input conversion works effectively.
Note
Alternative alphabets (used by MCA, MC1 and MC2 codes) can be set up via the denationalisation system. See the
Synonyms
The following synonym codes are also available:
MCAN Synonym for MCB.
MC/AN Synonym for MC/B.
MCD Synonym for MCDX.
MCI Synonym for MC0.
MCNA Synonym for MCB.
MC/NA Synonym for MC/B.
MCR Synonym for MCRD.
MCX Synonym for MCXD.
MX Synonym for MCAX.
MY Synonym for MCXA.
Changing Case
Some MC codes change letters from upper case to lower case or vice versa.
Input conversion
Input conversion does not invert. It applies the character conversion to the input data.
Codes
MCL Convert all upper case letters
MCT Convert all upper case letters
A word starts at the beginning of the string or with the first alphanumeric character following a space, double quotation mark, left parenthesis or hyphen.
MCU Convert all lower case letters
Examples
The following examples demonstrate changing case with MC codes. The first two examples translate a character string to upper case and lower case respectively. In the third example, the first letter of each word is translated to upper case and the remaining characters to lower case:
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCU |
|
|
MCL |
|
|
MCT |
|
|
Extracting Characters
Some MC codes extract characters from a string. The classes of characters that can be extracted are: alphabetic, non-alphabetic, numeric, non-numeric, alphanumeric and non-alphanumeric.
Input conversion
Input conversion does not invert. It applies the character conversion to the input data.
Codes
MC0 Extract only characters in standard alphabet.
MC1 Extract only characters in primary added alphabet.
MC2 Extract only characters in secondary added alphabet.
MCA Extract only characters in standard, primary added, and secondary added alphabets.
MC/A Extract only non-alphabetic characters.
MCB Extract only alphanumeric characters.
MC/B Extract only special characters that are neither alphabetic nor numeric.
MCN Extract only numeric characters
MC/N Extract only non-numeric characters.
Note
Alternative alphabets (used by MCA, MC1 and MC2 codes) can be set up via the denationalisation system. See the
Synonyms
MCAN is a synonym for MCB.
MC/AN is a synonym for MC/B.
MCNA is a synonym for MCB.
MC/NA is a synonym for MC/B.
Examples
In the following table, the first two examples extract only alphabetic or numeric characters respectively. The other two examples extract only alphanumeric characters or special characters respectively.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCA |
ABC;123/DEF |
|
MC/A |
ABC;123/DEF |
|
MCB |
ABC;123/DEF |
|
MC/B |
ABC;123/DEF |
|
Replacing Characters
Some MC codes replace some characters with other characters. These codes:
- exchange one character string for another;
- replace non-printable characters with a marker character;
- replace non-printable characters with a marker character and the character's hexadecimal representation;
- replace the marker and hexadecimal representation with the ASCII code.
Input conversion
Input conversion does not invert. It applies the character conversion to the input data.
Codes
MCC;x;yChange all occurrences of character string x to character string y.
MCP{c} Convert each non-printable character (X'00' to X'1F' and X'80' to X'FE') to a tilde (~) or to character c. If c is itself a tilde, all non-printable characters are removed.
MCPN{c} Convert each non-printable character (X'00' to X'1F' and X'80' to X'FE') to a tilde (~) or to character c, immediately followed by the two-character hexadecimal representation of the non-printable character. Any existing occurrences of character c are treated as if they are non-printable characters.
MCNP{c} Convert paired hexadecimal digits preceded by a tilde or character c to ASCII code. This code inverts the conversion performed by the MCPN code.
Examples
In the following example, the existing string 'A1B' is replaced by 'C2D'.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCC;A1B;C2D |
A1B567A1B |
|
In the following three examples, assume that x is CTRL+@ and y is CTRL+E. In the first example, non-printable characters are translated to tildes. In the second, they are translated to tildes followed by the two-character hexadecimal representation of the non-printable character. Finally, in the third example, non-printable characters are simply removed.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCP |
123xABCy456& |
|
MCPN |
123xABCy456& |
|
MCP~ |
123xABCy456& |
|
You can use the same codes but specify a character other than the default tilde to use as the substitution character. In the third example, the substitution character (&) already exists in the stored value and therefore its two-character hexadecimal representation (26) is inserted too.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCP= |
123xABCy456& |
|
MCPN# |
123xABCy456& |
|
MCPN& |
123xABCy456& |
|
The MCNP code inverts the results of the MCPN code:
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCNP |
123~00ABC~05456& |
|
MCNP# |
123#00ABC#05456& |
|
MCNP& |
123&00ABC&05456&26 |
|
Converting Character Codes
Some MC codes convert ASCII character codes to their binary or hexadecimal equivalents or vice versa.
Input conversion
Input conversion does not invert. It applies the character conversion to the input data.
Codes
MCAB{S} Convert ASCII character codes to binary representation (suppress spaces).
MCAX Convert ASCII character codes to hexadecimal representation.
MCBA Convert binary representation to ASCII characters.
MCXA Convert hexadecimal representation to ASCII characters.
Spaces between binary numbers
The codes MCAB and MCABS convert each ASCII character to its binary equivalent as an eight-digit number. If there is more than one character, MCAB puts a blank space between each pair of eight-digit numbers. MCABS suppresses the spaces.
When converting from binary to ASCII characters, MCBA uses blank spaces as dividers if they are present. MCBA effectively scans from the right end of the data looking for eight-bit chunks of binary digits. If the process encounters a blank space and the chunk is not a multiple of eight binary digits, it appends zeros to the front of the number until it has a multiple of eight digits. The process continues doing this until it gets to the leftmost digit, at which point it appends zeros if necessary. It then converts each eight-digit chunk into an ASCII character.
Synonyms
MX is a synonym for MCAX.
MCY is a synonym for MCXA.
Note
When you specify the codes MCBA or MCXA, you must take care that the codes do not cause unusual displays on the terminal screen or on a printer. The code X'0C', for example, is the clear screen code in ASCII. If you were to translate it using MCXA, it would clear the screen when it was sent to the terminal.
Examples
In the following example, the MCXA converts codes expressed as hexadecimal numbers to their ASCII equivalents. The MCAX does the reverse.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCXA |
412B423D43 |
|
MCAX |
Calif. |
|
In the following examples, MCAB converts letters to their binary equivalents with intervening spaces. MCABS does the same but without spaces. MCBA converts from binary representation to ASCII code.
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCAB |
FI |
|
MCABS |
FI |
|
MCBA |
01010111 01100101 |
|
MCBA |
1010111 1100101 |
|
MCBA |
101011101100101 |
|
Converting Numeric Values
Some MC codes convert numeric values, as opposed to characters, to their equivalents in other number bases or representation. There are MC codes for performing the following conversions:
- decimal to hexadecimal
- hexadecimal to decimal
- hexadecimal to binary
- binary to hexadecimal
- decimal (Arabic) numbers to Roman numerals
- Roman numerals to decimal (Arabic) numbers
Input conversion
Input conversion works for MCDR, MCDX, MCRD and MCXD. The other codes do not invert; they apply the character conversion to the input data.
Codes
MCBX Convert a binary value to its hexadecimal equivalent.
MCDR Convert a decimal value to its equivalent Roman numerals.
MCDX Convert a decimal value to its hexadecimal equivalent.
MCRD Convert Roman numerals to the decimal equivalent.
MCXB{S} Convert a hexadecimal value to its binary equivalent (suppress spaces).
MCXD Convert a hexadecimal value to its decimal equivalent.
Numeric value conversion
These codes convert numeric values as opposed to individual characters. Thus, the decimal number 67 converted to hexadecimal is X'43'; converted to Roman numerals, it is LXVII. The value of the number 67 is converted, not the characters "6" and "7."
Conversion stoppers
Except for MCBX{S}, these codes stop on a character that is not a digit of the number system. MCDX and MCDR stop on a nondecimal digit; MCRD stops on a non-Roman numeral; and MCXB and MCXD stop on a nonhexadecimal digit.
MCBX allows blank spaces as dividers between binary numbers; otherwise, it stops on a nonbinary digit.
When a conversion processor does not find any valid digits of its number system, it outputs a zero except for MCDR, which outputs null.
Odd number
MCXB converts a hexadecimal number to a binary number. Because the processor outputs binary numbers in eight-digit chunks, it must add a leading zero when processing an odd number of hexadecimal digits.
Spaces between binary numbers
The codes MCXB and MCXBS convert each hexadecimal digit to its binary equivalent as an eight-digit number. If there is more than one hexadecimal digit, MCAB puts a blank space between each pair of eight-digit numbers. MCABS suppresses the space.
When converting from binary to hexadecimal digits, MCBX uses blank spaces as dividers if they are present. MCBX effectively scans from the right end of the data looking for eight-bit chunks of binary digits. If the process encounters a blank space and the chunk is not a multiple of eight binary digits, it appends zeros to the front of the number until it has a multiple of eight digits. The process continues doing this until it gets to the leftmost digit, at which point it appends zeros if necessary. It then converts each eight-digit chunk into a hexadecimal digit.
Synonyms
MCD is a synonym for MCDX.
MCR is a synonym for MCRD.
MCX is a synonym for MCXD.
Examples
The following examples demonstrate the MC codes for converting numeric values:
MC Code |
Stored Value |
Converted Value |
---|---|---|
MCBX |
1111101001111101 |
|
MCBX |
101011 |
|
MCBX |
10 1011 |
|
MCXB |
2EA7 |
|
MCXB |
EA7 |
|
MCXBS |
2EA7 |
|
MCDR |
1989 |
|
MCRD |
MX |
|
MCDX |
154 |
|
MCXD |
AA |
|