Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!bacchus!mwm From: mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) Newsgroups: comp.sys.amiga.programmer Subject: Re: 4 bytes to a long? Message-ID: Date: 9 Jun 91 17:06:37 GMT References: <451.28517f01@beach.gal.utexas.edu> Sender: news@pa.dec.com (News) Organization: Missionaria Phonibalonica Lines: 28 In-Reply-To: mrimages@beach.gal.utexas.edu's message of 9 Jun 91 07:06:09 GMT In article <451.28517f01@beach.gal.utexas.edu> mrimages@beach.gal.utexas.edu writes: Is there a fast, simple way to convert 4 bytes into a long? I am doing it presently this way, but it seems kind of kludgy: union { long tlong; char tchar[4]; } mytime; for(i=0;i<4;i++) mytime.tchar[i]=block[i]; sprintf(tempstr,"%s",ctime(&mytime.tlong)); Any suggestions or is this the best I can do? It's not portable is one problem. Doing the conversion explicitly is both portable, and seems a little cleaner: sprintf(tempstr, "%s", ctime((((((block[3] << 8) + block[2]) << 8) + block[1]) << 8) + block[0]));