On Monday, Nov 10, 2003, at 11:03 US/Pacific, piclist@XARGS.COM wrote: > I assume you meant upper 8 bits? > > unsigned char c; > int i; > > c = i >> 8; > > generates optimal code. So will a union, but the above is more > portable. > >> right now I'm doing it like this: >> (char)(number/256) > > If "number" is an unsigned int, it will also generate optimal code; > i.e., it doesn't actually do a division. > Whether either of these statements will generate 'optimal' code is rather compiler dependent. Sure, it'd be nice if most c compilers optimized this, but I'm not sure that it's true. I was looking at the jal source code recently, and was rather shocked at its "lazy" implementation of multiply and divide, for instance. Look at the asm file generated, and see what it actually does... BillW -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.