data << 1; That does not assign the value back to data, does it? Not sure how it works for the lower 16 bit ;-)
Sergei > -----Original Message----- > From: mspgcc-users-ad...@lists.sourceforge.net > [mailto:mspgcc-users-ad...@lists.sourceforge.net] On Behalf > Of Peter Mueller > Sent: Tuesday, December 07, 2004 4:34 PM > To: mspgcc-users@lists.sourceforge.net > Subject: [Mspgcc-users] shift operation problem with "unsigned long" > > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi all, > > I'm writing an interface to a chip which provides its data > via a shift > register. > It looks like that shifting ones in the lower 16Bit of an > unsigned long > works fine. A bit shifted into the higher 16 Bits just gets lost. Is > this a known issue or maybe a sw-error on my side that I've just > overseen? > > My code looks in principle like: > > - ----- > unsigned long data=0; > unsigned char n; > > for (i=0; i<25; i++){ > > // set clock high > n = P1IN & 0x1; > // set clock low > if(n){ > data |= 1; // shift in a one > data << 1; > }else{ > data <<1; // shift in a zero > } > > printf("%x ", data); > } > - ---- > > For a given input stream the output looks like: 2 4 8 10 20 40 82 106 > 20c 418 830 1060 20c0 4180 8300 600 c00 1800 3000 6000 c000 8000 0 0 > > One can see that after shifting the next bit into 0x8000 the > result is > 0 but should be 0x10000. > > Thanks for your help, > Peter > > P.S: I use msp430-gcc version 3.2.3 on a windows box > > > > Peter Mueller > peter.o.muel...@gmx.de > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.3 (Darwin) > > iD8DBQFBti/kUzCcwYQMTJoRAq8SAJ9wGEdP8WdecbhenUf4QXGWvg/+fQCfXyWu > Bcls7NaUVSda+E0cH0HghPY= > =wx9e > -----END PGP SIGNATURE----- > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from > real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users >