Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!haven!decuac!mountn.dec.com!labc!wallis From: wallis@labc.dec.com (Barry L. Wallis) Newsgroups: comp.lang.c Subject: Re: A Simple question Summary: signed vs. unsigned chars Message-ID: <1524@mountn.dec.com> Date: 11 Apr 90 05:25:24 GMT Sender: news@mountn.dec.com Organization: Digital Equipment Corporation Lines: 29 In article <1881@zipeecs.umich.edu>, yhe@zip.eecs.umich.edu (Youda He) writes... !>Here is the sample program: !>main() !>{ !> char a=255; !> unsigned char b = 255; !> printf("a=%X\n",a); !> printf("b=%X\n",b); !>} !> !>The result is !>a=FFFF !>b=FF !>on dos, by using zortech and mcs, char is 8 bit long, why a looks like 16bit? !>what is the difference of char and unsigned char on printf? !> !>-- Youda The %X specifier in printf() tells the function to interpret the argument as an int. Since the actual value is a char it is pushed on the stack as an int. If the value pushed is defined as a signed char (as 'a' is), the high order bit is sign extended; otherwise the high order byte is 00. --- Barry L. Wallis USENET: wallis@labc.dec.com Database Consultant Prodigy (don't laugh): DNMX41A U.S. DECtp Resource Center DECUServe: EISNER::WALLIS (not on the net yet) Los Angeles, CA "No one voted for me, I represent myself" ---