EBCDIC <--> ASCII conversion

Jan Christiaan van Winkel jc at atcmp.nl
Fri Oct 12 21:44:02 AEST 1990


>From article <661 at modus.sublink.ORG>, by luke at modus.sublink.ORG (Luciano Mannucci):
| In article <1756 at dinl.mmc.UUCP>, noren at dinl.uucp (Charles Noren) writes:
|> via TCP/IP.  Our question, is there any program in Netland
|> that converts back and forth between EBCDIC and ASCII
| 
| static char _tob[] = {
| 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f,
.
.
| 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xc0,0x6a,0xd0,0xa1,0x07,
| };

| static char _toa[] = {
| 0x00,0x01,0x02,0x03,0x00,0x09,0x00,0x7f,0x00,0x00,0x00,0x0b,0x0c,0x0d,0x0e,0x0f,
.
.
| 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x00,0x00,0x00,0x00,0x00,0x00,
| };
| 
| char btoa(c)
| char c;
| {
| 	if (c < 0) return -1;
| 	return _toa[c];
| }
This is *THE* case where you need unsigned char's in stead of plain char's
The problem is that ebcdic uses the full range from 0 to 255 for it's char's.
for example the ebcdic code for '3' is 0xf3. On a machine
that uses signed characters for plain char's, the number in c will be inter-
preted as a negative number fooling your test in btoa...
JC
-- 
___  __  ____________________________________________________________________
   |/  \   Jan Christiaan van Winkel      Tel: +31 80 566880  jc at atcmp.nl
   |       AT Computing   P.O. Box 1428   6501 BK Nijmegen    The Netherlands
__/ \__/ ____________________________________________________________________



More information about the Comp.lang.c mailing list