Xref: utzoo comp.lang.c:16614 comp.sys.amiga:30001 Path: utzoo!attcan!uunet!lll-winken!ames!xanth!byrum From: byrum@cs.odu.edu (Terry Franklin Byrum) Newsgroups: comp.lang.c,comp.sys.amiga Subject: Re: printf in dump routine Keywords: printf, pointers Message-ID: <7952@xanth.cs.odu.edu> Date: 1 Mar 89 15:19:56 GMT References: <652@dsacg2.UUCP> Followup-To: comp.lang.c Organization: Old Dominion University, Norfolk, Va. Lines: 42 Try this instead... void print_data(pnt,num) unsigned char *pnt; int num; { int i; for(i = num - 1; i >= 0; i--) printf("%02x ",*(pnt + i)); } > ... There I got 'ffd2040000', which except for the leading 'ff' looks > like it was printing the bytes backwards. Any clues ... Have you ever heard of low-high (Little Endian) architecture. Most PC type computers store values least significant byte first. If you want a number written (normally) you must scan backwards. Also, on most PC machines char is signed by default. Due to sign extension, if the byte value is greater than 7F Hex, unwanted leading FFs will appear on promotion to int. The solution is to specify unsigned char* instead of char*, either as the function's formal parameter or as a cast within the printf argument. ... Frank Frank Byrum, BROOKS Financial Systems, Suffolk VA, (804)539-7202 1st Law of SE INET:byrum@cs.odu.edu UUCP:..!sun!xanth!{byrum,brooks!frank} Semper Sic Factum -- Inventions have long since reached their limit -- and I see no hope for further developments. - Julius Frontinus, world famous engineer, Rome, 10 AD | Terry Franklin (Frank) Byrum | BROOKS Financial Systems, Inc. ___ | INET: byrum@cs.odu.edu /__ _. __. _ _ /_ | UUCP: ...!sun!xanth!brooks!byrum / _/ \_(_/|_|\|_/ \ | DISCLAIMER: No one listens anyway!