toascii() — Translate integer to a 7-bit ASCII character

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both POSIX(ON)

Format

_XOPEN_SOURCE
#define _XOPEN_SOURCE
#include <ctype.h>

int toascii(int c);
_ALL_SOURCE
#define _ALL_SOURCE
#include <ctype.h>

int toascii(int c);

General description

Special behavior for _XOPEN_SOURCE: The toascii() function converts its argument to a 7-bit US-ASCII character code.

The toascii() function is not intended to be used to convert EBCDIC characters to ASCII, attempts to use it in this manner will not function as expected.

Special behavior for _ALL_SOURCE: The toascii() function assumes c modulo 256 is a single-byte EBCDIC encoding for a Latin 1 character, <input-character>, in the current locale. Then, toascii() determines to what character, <output-character>, toascii() would map <input-character> in an ASCII locale (for example, on an *IX system) and returns the EBCDIC encoding for <output-character> in the current locale.

For example, if the program invoking toascii() was compiled with _ALL_SOURCE defined and if the value c input to toascii() modulo 256 is the EBCDIC encoding for <international-currency-symbol> in the current locale, toascii() returns the EBCDIC encoding for <dollar> in the current locale because toascii() maps <international-currency-symbol> to <dollar> on ASCII platforms.

Returned value

EBCDIC and ASCII encodings and <input-character> to <output-character> mapping performed by toascii() in an IBM-1047 locale are as follows:
/*********************************************************************/
/*                                                                   */
/*  IBM-1047 toascii table  (sorted by ebcdic)                       */
/*                                                                   */
/*    For ISO-8859 character encoding toascii(ch) returns ch for     */
/*    values of ch less than 128 and ch-128 for values between       */
/*    128 and 255, inclusive. Table below shows corresponding        */
/*    toascii(ch) equivalence for IBM-1047 character encoding        */
/*    of the Latin character set.                                    */
/*                                                                   */
/*                         IBM 1047               ISO 8859-1         */
/*    Character            Encoding               Encoding           */
/* (Symbolic Name)         (Hexadecimal)          (Hexadecimal)      */
/*                                                                   */
/*   ch     toascii(ch)    ch  toascii(ch)        ch  toascii(ch)    */
/*                                                                   */
/*  <NUL>      <NUL>       00      00             00      00         */
/*  <SOH>      <SOH>       01      01             01      01         */
/*  <STX>      <STX>       02      02             02      02         */
/*  <ETX>      <ETX>       03      03             03      03         */
/*  <SEL>      <IFS/IS4>   04      1C             9C      1C         */
/*  <HT>       <HT>        05      05             09      09         */
/*  <RNL>      <ACK>       06      2E             86      06         */
/*  <DEL>      <DEL>       07      07             7F      7F         */
/*  <GE>       <ETB>       08      26             97      17         */
/*  <SPS>      <CR>        09      0D             8D      0D         */
/*  <RPT>      <SO>        0A      0E             8E      0E         */
/*  <VT>       <VT>        0B      OB             0B      0B         */
/*  <FF>       <FF>        0C      0C             0C      0C         */
/*  <CR>       <CR>        0D      0D             0D      OD         */
/*  <SO>       <SO>        0E      0E             0E      OE         */
/*  <SI>       <SI>        0F      0F             0F      0F         */
/*  <DLE>      <DLE>       10      10             10      10         */
/*  <DC1>      <DC1>       11      11             11      11         */
/*  <DC2>      <DC2>       12      12             12      12         */
/*  <DC3>      <DC3>       13      13             13      13         */
/*  <RES/ENP>  <IGS/IS3>   14      1D             9D      1D         */
/*  <NL>       <NL>        15      15             0A      0A         */
/*  <BS>       <BS>        16      16             08      08         */
/*  <POC>      <BEL>       17      2F             87      07         */
/*  <CAN>      <CAN>       18      18             18      18         */
/*  <EM>       <EM>        19      19             19      19         */
/*  <UBS>      <DC2>       1A      12             92      12         */
/*  <CU1>      <SI>        1B      0F             8F      0F         */
/*  <IFS/IS4>  <IFS/IS4>   1C      1C             1C      1C         */
/*  <IGS/IS3>  <IGS/IS3>   1D      1D             1D      1D         */
/*  <IRS/IS2>  <IRS/IS2>   1E      1E             1E      1E         */
/*  <IUS/IS1>  <IUS/IS1>   1F      1F             1F      1F         */
/*  <DS>       <NUL>       20      00             80      00         */
/*  <SOS>      <SOH>       21      01             81      01         */
/*  <FS>       <STX>       22      02             82      02         */
/*  <WUS>      <ETX>       23      03             83      03         */
/*  <BYP/INP>  <EOT>       24      37             84      04         */
/*  <LF>       <ENQ>       25      2D             85      05         */
/*  <ETB>      <ETB>       26      26             17      17         */
/*  <ESC>      <ESC>       27      27             1B      1B         */
/*  <SA>       <BS>        28      16             88      08         */
/*  <SFE>      <HT>        29      05             89      09         */
/*  <SM/SW>    <NL>        2A      15             8A      0A         */
/*  <CSP>      <VT>        2B      0B             8B      0B         */
/*  <MFA>      <FF>        2C      0C             8C      0C         */
/*  <ENQ>      <ENQ>       2D      2D             05      05         */
/*  <ACK>      <ACK>       2E      2E             06      06         */
/*  <BEL>      <BEL>       2F      2F             07      07         */
/*  (reserved) <DLE>       30      10             90      10         */
/*  (reserved) <DC1>       31      11             91      11         */
/*  <SYN>      <SYN>       32      32             16      16         */
/*  <IR>       <DC3>       33      13             93      13         */
/*  <PP>       <DC4>       34      3C             94      14         */
/*  <TRN>      <NAK>       35      3D             95      15         */
/*  <NBS>      <SYN>       36      32             96      16         */
/*  <EOT>      <EOT>       37      37             04      04         */
/*  <SBS>      <CAN>       38      18             98      18         */
/*  <IT>       <EM>        39      19             99      19         */
/*  <RFF>      <SUB>       3A      3F             9A      1A         */
/*  <CU3>      <ESC>       3B      27             9B      1B         */
/*  <DC4>      <DC4>       3C      3C             14      14         */
/*  <NAK>      <NAK>       3D      3D             15      15         */
/*  (reserved) <IRS/IS2>   3E      1E             9E      1E         */
/*  <SUB>      <SUB>       3F      3F             1A      1A         */
/*                                                                   */
/*  <space>    <space>     40      40             20      20         */
/*  <nobrk-sp> <space>     41      40             A0      20         */
/*  <a-circum> <b>         42      82             E2      62         */
/*  <a-diaere> <d>         43      84             E4      64         */
/*  <a-grave>  <grave>     44      79             E0      60         */
/*  <a-acute>  <a>         45      81             E1      61         */
/*  <a-tilde>  <c>         46      83             E3      63         */
/*  <a-ring>   <e>         47      85             E5      65         */
/*  <c-cedilla><g>         48      87             E7      67         */
/*  <n-tilde>  <q>         49      98             F1      71         */
/*  <cent-sign><quote>     4A      7F             A2      22         */
/*  <period>   <period>    4B      4B             2E      2E         */
/*  <lt>       <lt>        4C      4C             3C      3C         */
/*  <l-paren>  <l-paren>   4D      4D             28      28         */
/*  <plus>     <plus>      4E      4E             2B      2B         */
/*  <ver-line> <ver-line>  4F      4F             7C      7C         */
/*  <ampersand><ampersand> 50      50             26      26         */
/*  <e-acute>  <i>         51      89             E9      69         */
/*  <e-circum> <j>         52      91             EA      6A         */
/*  <e-diaere> <k>         53      92             EB      6B         */
/*  <e-grave>  <h>         54      88             E8      68         */
/*  <i-acute>  <m>         55      94             ED      6D         */
/*  <i-circum> <n>         56      95             EE      6E         */
/*  <i-diaere> <o>         57      96             EF      6F         */
/*  <i-grave>  <l>         58      93             EC      6C         */
/*  <s-sharp>  <underscr>  59      6D             DF      5F         */
/*  <exclama>  <exclama>   5A      5A             21      21         */
/*  <dollar>   <dollar>    5B      5B             24      24         */
/*  <asterisk> <asterisk>  5C      5C             2A      2A         */
/*  <r-paren>  <r-paren>   5D      5D             29      29         */
/*  <semicolon><semicolon> 5E      5E             3B      3B         */
/*  <circum>   <circum>    5F      5F             5E      5E         */
/*  <hyphen>   <hyphen>    60      60             2D      2D         */
/*  <slash>    <slash>     61      61             2F      2F         */
/*  <A-circum> <B>         62      C2             C2      42         */
/*  <A-diaere> <D>         63      C4             C4      44         */
/*  <A-grave>  <at>        64      7C             C0      40         */
/*  <A-acute>  <A>         65      C1             C1      41         */
/*  <A-tilde>  <C>         66      C3             C3      43         */
/*  <A-ring>   <E>         67      C5             C5      45         */
/*  <C-cedilla><G>         68      C7             C7      47         */
/*  <N-tilde>  <Q>         69      D8             D1      51         */
/*  <brok-bar> <ampersand> 6A      50             A6      26         */
/*  <comma>    <comma>     6B      6B             2C      2C         */
/*  <percent>  <percent>   6C      6C             25      25         */
/*  <underscr> <underscr>  6D      6D             5F      5F         */
/*  <gt>       <gt>        6E      6E             3E      3E         */
/*  <question> <question>  6F      6F             3F      3F         */
/*  <o-stroke> <x>         70      A7             F8      78         */
/*  <E-acute>  <I>         71      C9             C9      49         */
/*  <E-circum> <J>         72      D1             CA      4A         */
/*  <E-diaere> <K>         73      D2             CB      4B         */
/*  <E-grave>  <H>         74      C8             C8      48         */
/*  <I-acute>  <M>         75      D4             CD      4D         */
/*  <I-circum> <N>         76      D5             CE      4E         */
/*  <I-diaere> <O>         77      D6             CF      4F         */
/*  <I-grave>  <L>         78      D3             CC      4C         */
/*  <grave>    <grave>     79      79             60      60         */
/*  <colon>    <colon>     7A      7A             3A      3A         */
/*  <num-sign> <num-sign>  7B      7B             23      23         */
/*  <at>       <at>        7C      7C             40      40         */
/*  <apostro>  <apostro>   7D      7D             27      27         */
/*  <eq>       <eq>        7E      7E             3D      3D         */
/*  <quote>    <quote>     7F      7F             22      22         */
/*  <O-stroke> <X>         80      E7             D8      58         */
/*  <a>        <a>         81      81             61      61         */
/*  <b>        <b>         82      82             62      62         */
/*  <c>        <c>         83      83             63      63         */
/*  <d>        <d>         84      84             64      64         */
/*  <e>        <e>         85      85             65      65         */
/*  <f>        <f>         86      86             66      66         */
/*  <g>        <g>         87      87             67      67         */
/*  <h>        <h>         88      88             68      68         */
/*  <i>        <i>         89      89             69      69         */
/*  <l-guille> <plus>      8A      4E             AB      2B         */
/*  <r-guille> <semicolon> 8B      5E             BB      3B         */
/*  <eth>      <p>         8C      97             F0      70         */
/*  <y-acute>  <r-brace>   8D      D0             FD      7D         */
/*  <thorn>    <tilde>     8E      A1             FE      7E         */
/*  <plusminus><one>       8F      F1             B1      31         */
/*  <degree>   <zero>      90      F0             B0      30         */
/*  <j>        <j>         91      91             6A      6A         */
/*  <k>        <k>         92      92             6B      6B         */
/*  <l>        <l>         93      93             6C      6C         */
/*  <m>        <m>         94      94             6D      6D         */
/*  <n>        <n>         95      95             6E      6E         */
/*  <o>        <o>         96      96             6F      6F         */
/*  <p>        <p>         97      97             70      70         */
/*  <q>        <q>         98      98             71      71         */
/*  <r>        <r>         99      99             72      72         */
/*  <fem-ind>  <asterisk>  9A      5C             AA      2A         */
/*  <mas-ind>  <colon>     9B      7A             BA      3A         */
/*  <ae>       <f>         9C      86             E6      66         */
/*  <cedilla>  <eight>     9D      F8             B8      38         */
/*  <AE>       <F>         9E      C6             C6      46         */
/*  <cur-sign> <dollar>    9F      5B             A4      24         */
/*  <mu>       <five>      A0      F5             B5      35         */
/*  <tilde>    <tilde>     A1      A1             7E      7E         */
/*  <s>        <s>         A2      A2             73      73         */
/*  <t>        <t>         A3      A3             74      74         */
/*  <u>        <u>         A4      A4             75      75         */
/*  <v>        <v>         A5      A5             76      76         */
/*  <w>        <w>         A6      A6             77      77         */
/*  <x>        <x>         A7      A7             78      78         */
/*  <y>        <y>         A8      A8             79      79         */
/*  <z>        <z>         A9      A9             7A      7A         */
/*  <inv-excl> <exclama>   AA      5A             A1      21         */
/*  <inv-ques> <question>  AB      6F             BF      3F         */
/*  <Eth>      <P>         AC      D7             D0      50         */
/*  <l-brk>    <l-brk>     AD      AD             5B      5B         */
/*  <Thorn>    <circum>    AE      5F             DE      5E         */
/*  <register> <period>    AF      4B             AE      2E         */
/*  <not-sign> <comma>     B0      6B             AC      2C         */
/*  <pound>    <num-sign>  B1      7B             A3      23         */
/*  <yen>      <percent>   B2      6C             A5      25         */
/*  <mid-dot>  <seven>     B3      F7             B7      37         */
/*  <copyright><r-paren>   B4      5D             A9      29         */
/*  <section>  <apostro>   B5      7D             A7      27         */
/*  <paragraph><six>       B6      F6             B6      36         */
/*  <1/4>      <lt>        B7      4C             BC      3C         */
/*  <1/2>      <eq>        B8      7E             BD      3D         */
/*  <3/4>      <gt>        B9      6E             BE      3E         */
/*  <Y acute>  <r-brk>     BA      BD             DD      5D         */
/*  <diaeresis><l-paren>   BB      4D             A8      28         */
/*  <macron>   <slash>     BC      61             AF      2F         */
/*  <r-brk>    <r-brk>     BD      BD             5D      5D         */
/*  <acute>    <four>      BE      F4             B4      34         */
/*  <multiply> <W>         BF      E6             D7      57         */
/*  <l-brace>  <l-brace>   C0      C0             7B      7B         */
/*  <A>        <A>         C1      C1             41      41         */
/*  <B>        <B>         C2      C2             42      42         */
/*  <C>        <C>         C3      C3             43      43         */
/*  <D>        <D>         C4      C4             44      44         */
/*  <E>        <E>         C5      C5             45      45         */
/*  <F>        <F>         C6      C6             46      46         */
/*  <G>        <G>         C7      C7             47      47         */
/*  <H>        <H>         C8      C8             48      48         */
/*  <I>        <I>         C9      C9             49      49         */
/*  <soft-hyp> <hyphen>    CA      60             AD      2D         */
/*  <o-circum> <t>         CB      A3             F4      74         */
/*  <o-diaere> <v>         CC      A5             F6      76         */
/*  <o-grave>  <r>         CD      99             F2      72         */
/*  <o-acute>  <s>         CE      A2             F3      73         */
/*  <o-tilde>  <u>         CF      A4             F5      75         */
/*  <r-brace>  <r-brace>   D0      D0             7D      7D         */
/*  <J>        <J>         D1      D1             4A      4A         */
/*  <K>        <K>         D2      D2             4B      4B         */
/*  <L>        <L>         D3      D3             4C      4C         */
/*  <M>        <M>         D4      D4             4D      4D         */
/*  <N>        <N>         D5      D5             4E      4E         */
/*  <O>        <O>         D6      D6             4F      4F         */
/*  <P>        <P>         D7      D7             50      50         */
/*  <Q>        <Q>         D8      D8             51      51         */
/*  <R>        <R>         D9      D9             52      52         */
/*  <super-1>  <nine>      DA      F9             B9      39         */
/*  <u-circum> <l-brace>   DB      C0             FB      7B         */
/*  <u-diaere> <ver_line>  DC      4F             FC      7C         */
/*  <u-grave>  <y>         DD      A8             F9      79         */
/*  <u-acute>  <z>         DE      A9             FA      7A         */
/*  <y-diaere> <DEL>       DF      07             FF      7F         */
/*  <backslash><backslash> E0      E0             5C      5C         */
/*  <division> <w>         E1      A6             F7      77         */
/*  <S>        <S>         E2      E2             53      53         */
/*  <T>        <T>         E3      E3             54      54         */
/*  <U>        <U>         E4      E4             55      55         */
/*  <V>        <V>         E5      E5             56      56         */
/*  <W>        <W>         E6      E6             57      57         */
/*  <X>        <X>         E7      E7             58      58         */
/*  <Y>        <Y>         E8      E8             59      59         */
/*  <Z>        <Z>         E9      E9             5A      5A         */
/*  <super-2>  <two>       EA      F2             B2      32         */
/*  <O-circum> <T>         EB      E3             D4      54         */
/*  <O-diaere> <V>         EC      E5             D6      56         */
/*  <O-grave>  <R>         ED      D9             D2      52         */
/*  <O-acute>  <S>         EE      E2             D3      53         */
/*  <O-tilde>  <U>         EF      E4             D5      55         */
/*  <zero>     <zero>      F0      F0             30      30         */
/*  <one>      <one>       F1      F1             31      31         */
/*  <two>      <two>       F2      F2             32      32         */
/*  <three>    <three>     F3      F3             33      33         */
/*  <four>     <four>      F4      F4             34      34         */
/*  <five>     <five>      F5      F5             35      35         */
/*  <six>      <six>       F6      F6             36      36         */
/*  <seven>    <seven>     F7      F7             37      37         */
/*  <eight>    <eight>     F8      F8             38      38         */
/*  <nine>     <nine>      F9      F9             39      39         */
/*  <super-3>  <three>     FA      F3             B3      33         */
/*  <U-circum> <l-brk>     FB      AD             DB      5B         */
/*  <U-diaere> <backslash> FC      E0             DC      5C         */
/*  <U-grave>  <Y>         FD      E8             D9      59         */
/*  <U-acute>  <Z>         FE      E9             DA      5A         */
/*  <EO>       <IUS/IS1>   FF      1F             9F      1F         */
/*                                                                   */
/*********************************************************************/

Special behavior for _XOPEN_SOURCE: The toascii() function returns the value (c & 0x7f).

Special behavior for _ALL_SOURCE: If the current locale is not a single-byte locale (that is, mb_cur_max > 1), toascii() sets errno to ENOSYS and returns -1. Otherwise, toascii() assumes c modulo 256 is the encoding of a Latin 1 character, <input_character>, in the current locale and returns the EBCDIC encoding of the same or another Latin 1 character, <output-character>, in the current locale; where <output-character> corresponds to the character to which toascii() would map <input-character> on an ASCII platform.

Related information