Xref: utzoo comp.unix.misc:309 comp.lang.c:32820 Path: utzoo!attcan!uunet!midway!ncar!asuvax!cs.utexas.edu!sdd.hp.com!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!sci.kun.nl!atcmpe!jc From: jc@atcmp.nl (Jan Christiaan van Winkel) Newsgroups: comp.unix.misc,comp.lang.c Subject: Re: EBCDIC <--> ASCII conversion Message-ID: <671@atcmpe.atcmp.nl> Date: 12 Oct 90 11:44:02 GMT References: <661@modus.sublink.ORG> Organization: AT Computing, Nijmegen, The Netherlands Lines: 36 From article <661@modus.sublink.ORG>, by luke@modus.sublink.ORG (Luciano Mannucci): | In article <1756@dinl.mmc.UUCP>, noren@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@atcmp.nl | AT Computing P.O. Box 1428 6501 BK Nijmegen The Netherlands __/ \__/ ____________________________________________________________________