Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!elroy.jpl.nasa.gov!ncar!mephisto!prism!cc100aa From: cc100aa@prism.gatech.EDU (Ray Spalding) Newsgroups: comp.lang.c Subject: Re: binary to ascii Keywords: binary, ascii, translation Message-ID: <13680@hydra.gatech.EDU> Date: 14 Sep 90 18:00:34 GMT References: <371@bally.Bally.COM> <574@demott.COM> Distribution: usa Organization: Georgia Institute of Technology Lines: 16 In article <574@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes: >In article <371@bally.Bally.COM> siva@bally.Bally.COM (Siva Chelliah) writes: >> i=(int ) c; >> i=i & 0x00FF; /* this is necessary because when you read, sign is >> extended in c */ > Try "i = (unsigned int) c;" and you'll see it isn't necessary. This is incorrect (where c is a signed char). When converting from a signed integral type to a wider, unsigned one, sign extention IS performed (in two's complement representations). See K&R II section A6.2, "Integral Conversions". -- Ray Spalding, Technical Services, Office of Information Technology Georgia Institute of Technology, Atlanta Georgia, 30332-0275 uucp: ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!cc100aa Internet: cc100aa@prism.gatech.edu