I am trying to put a signed 16 bit number into the rightmost 16 bits
of a u32 buffer.
I have something that nearly works:
test = (analogue_out(0) < 0 ) ?
0x8000 | (u32)(analogue_out(0) * scale(0) * -3276.7) :
0x | (u32)(analogue_out(0) * scale(0) * 3276.7);
(Though, unexpec
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) s
On 1 April 2011 06:02, Pavel Shramov wrote:
> u32_var = ((u32) (u16) s16_var);
>
> u16 casts s16 to 16 bit positive number.
So, (s16)-10 == 32778?
(I could just check, but I won't be near a C compiler until sunday)
--
atp
"Torque wrenches are for the obedience of fools and the guidance of wis
On Fri, Apr 01, 2011 at 09:34:20AM +0100, andy pugh wrote:
> On 1 April 2011 06:02, Pavel Shramov wrote:
>
> > u32_var = ((u32) (u16) s16_var);
> >
> > u16 casts s16 to 16 bit positive number.
>
> So, (s16)-10 == 32778?
(s16) -10 == -10
(u16) -10 == 0xfff6
You may check it with shell:
$ printf
How about a union? I don't know the exact syntax off hand, but I know
it will do exactly what you are trying.
Brian
On Fri, Apr 1, 2011 at 4:57 AM, Pavel Shramov wrote:
> On Fri, Apr 01, 2011 at 09:34:20AM +0100, andy pugh wrote:
>> On 1 April 2011 06:02, Pavel Shramov wrote:
>>
>> > u32_var =
On Fri, Apr 01, 2011 at 09:35:35PM -0400, Brian wrote:
> How about a union? I don't know the exact syntax off hand, but I know
> it will do exactly what you are trying.
By the way great idea - it'll simplify code for futher authors.
But union is not needed here - struct is sufficient.
Something l