Search Linux Wireless

Re: [PATCH 2/6] b43: N-PHY: add RSSI functions: poll and set 2055 vcm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 11 January 2010 03:38:53 Larry Finger wrote:
> Yes, my fault. The specs are now corrected so that these statements are
> 
> ((s8)((s[1] >> 8) & 0x3F) << 2) >> 2
> 
> I think that is right.

No it is not.

You need to do this:
(s8)(((s[1] >> 8) & 0x3F) << 2) >> 2

Alternatively add another pair of parenthesis to make it clearer:

((s8)(((s[1] >> 8) & 0x3F) << 2)) >> 2

This basically shifts left unsigned and then shifts right _arithmetically_.
In your example, the compiler will optimize both shifts away (it may actually
also optimize the shifts in my case, but the sign extension will persist.

Just try it and you'll see:

mb@homer:~$ cat t.c
#include <stdio.h>
#include <stdint.h>

int main()
{
        int8_t s0;
        int8_t s1;
        uint8_t u;

        u = 0x3D;

        s0 = ((int8_t)(u & 0x3F) << 2) >> 2;
        s1 = ((int8_t)((u & 0x3F) << 2)) >> 2;

        printf("%d %d\n", s0, s1);
}
mb@homer:~$ gcc -o t t.c
mb@homer:~$ ./t
61 -3


-- 
Greetings, Michael.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux