On Fri, Apr 01, 2011 at 01:13:54AM +0100, andy pugh wrote: > I am trying to put a signed 16 bit number into the rightmost 16 bits > of a u32 buffer.
> However, surely there must be a tidier and faster way? (probably using > s16 typecasting and a bitwise OR? Yes, there is. u32_var = ((u32) (u16) s16_var); u16 casts s16 to 16 bit positive number. u32 cast converts 16 bit to 32 bit with with 0x0000 on the left So you'll get your number in lower part of u32. Just for sure you may add '& 0xffff' to ensure that other bits are zero (and omit u16 conversion). Pavel ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ Emc-developers mailing list Emc-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-developers