Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!inmet!ishmael!inmet!rich From: rich@inmet Newsgroups: comp.sys.amiga Subject: Re: printf in dump routine Message-ID: <204400008@inmet> Date: 2 Mar 89 19:26:00 GMT References: <652@dsacg2.UUCP> Lines: 41 Nf-ID: #R:dsacg2.UUCP:-65200:inmet:204400008:000:1447 Nf-From: inmet!rich Mar 2 14:26:00 1989 ] /* Written 2:04 pm Feb 28, 1989 by nor1675@dsacg2.UUCP in inmet:comp.sys.amiga */ ] . ] long test_long; ] test_long = 1234; ] print_data((char *)&test_long,sizeof(test_long)); ] . ] . ] void print_data(pnt,num) ] char *pnt; ] int num; ] { ] int i; ] for(i = 0; i < num; i++) ] { ] printf("%02x",*(pnt + i)); ] } ] } ] . ] What I would hope to get from this is '000004d2' but actually got ] '000004ffffffd2'. This was done with Lattice v5.0.1. I also tried ] similar code at work on a PC with MS v5.1. There I got 'ffd2040000', ] which except for the leading 'ff' looks like it was printing the bytes ] backwards. Any clues as to why I'm getting this output and how to do it ] right? Thanks ] ->Mike<- ] You have hit the infamous byte ordering and sign extension problems. You are not printing out the value of the long in your code, you are printing out the representation. Since the byte ordering is different between Ami's 68k and Pc's 80x8x, you get different result. The 'f's are probably from some sign extension somewhere, use 'unsigned char' instead of plain char (which can be sign or unsign) and it should be better ---------------------------------------------------------------- "I don't have to worry about the greenhouse effect: nuclear winter will compensate for it." Richard F. Man ...!uunet!inmet!rich