Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430



Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | MSP430 | How can shift more than 15 bits in 430?

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

How can shift more than 15 bits in 430? - =?GB2312?B?zuLU8bS+?= - Aug 5 9:52:26 2009

Hi All:

I am confusing about the shift operation in MSP430, when I shift more than
15 bits to a 32bit number, the complier says "shift count is too large".

what I wrote in C is :

unsigned long AckResult = 0; /* AckResult is 32 bit long */

AckResult |= (1<<31); /* the compiler warning here */

I have test:

1):
AckResult |= (1<<14); /*AckResult is OK:
0b00000000000000000100000000000000 */
2):
AckResult |= (1<<15); /*AckResult is not :
0b11111111111111111000000000000000 */
3):
when 1<<16 or 17 and so on, AckResult is
0b00000000000000000000000000000000.

The problem is, how can I set the MSBs of a unsigned long.
Can anyone help me? thanks.
[Non-text portions of this message have been removed]

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Re: How can shift more than 15 bits in 430? - Paul Curtis - Aug 5 9:55:50 2009

On Wed, 05 Aug 2009 14:51:17 +0100, =E5=90=B4=E6=8B=A9=E6=B7=B3 ail.com> wrote:

> Hi All:
>
> I am confusing about the shift operation in MSP430, when I shift more =
=20
> than
> 15 bits to a 32bit number, the complier says "shift count is too large".
>
> what I wrote in C is :
>
> unsigned long AckResult =3D 0; /* AckResult is 32 bit long */
>
> AckResult |=3D (1<<31); /* the compiler warning here */

1 is an int. 1<<15 =3D 0x8000, 1<<16 =3D 0. 1L is a long. 1L<<15 =3D 0x8=
000.=20=20=20
1L<<16=3D0x10000.

-- Paul.

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: How can shift more than 15 bits in 430? - old_cow_yellow - Aug 5 10:56:05 2009

Your problem is in c, not in 430.

--- In m...@yahoogroups.com, =CE=E2=D4=F1=B4=BE wrote:
>
> Hi All:
>=20
> I am confusing about the shift operation in MSP430, when I shift more tha=
n
> 15 bits to a 32bit number, the complier says "shift count is too large".
>=20
> what I wrote in C is :
>=20
> unsigned long AckResult =3D 0; /* AckResult is 32 bit long */
>=20
> AckResult |=3D (1<<31); /* the compiler warning here */
>=20
> I have test:
>=20
> 1):
> AckResult |=3D (1<<14); /*AckResult is OK:
> 0b00000000000000000100000000000000 */
> 2):
> AckResult |=3D (1<<15); /*AckResult is not :
> 0b11111111111111111000000000000000 */
> 3):
> when 1<<16 or 17 and so on, AckResult is
> 0b00000000000000000000000000000000.
>=20
> The problem is, how can I set the MSBs of a unsigned long.
> Can anyone help me? thanks.
>=20
>=20
> [Non-text portions of this message have been removed]
>
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: How can shift more than 15 bits in 430? - Preston Gurd - Aug 5 11:08:39 2009


You need to write "(1L<<31)" to force the constant 1 to be long.

On Wed, 5 Aug 2009, old_cow_yellow wrote:

> Your problem is in c, not in 430.
>=20
> --- In m...@yahoogroups.com, =CE=E2=D4=F1=B4=BE wrote:
> >
> > Hi All:
> >=20
> > I am confusing about the shift operation in MSP430, when I shift more t=
han
> > 15 bits to a 32bit number, the complier says "shift count is too large"=
.
> >=20
> > what I wrote in C is :
> >=20
> > unsigned long AckResult =3D 0; /* AckResult is 32 bit long */
> >=20
> > AckResult |=3D (1<<31); /* the compiler warning here */
> >=20
> > I have test:
> >=20
> > 1):
> > AckResult |=3D (1<<14); /*AckResult is OK:
> > 0b00000000000000000100000000000000 */
> > 2):
> > AckResult |=3D (1<<15); /*AckResult is not :
> > 0b11111111111111111000000000000000 */
> > 3):
> > when 1<<16 or 17 and so on, AckResult is
> > 0b00000000000000000000000000000000.
> >=20
> > The problem is, how can I set the MSBs of a unsigned long.
> > Can anyone help me? thanks.
> >=20
> >=20
> > [Non-text portions of this message have been removed]
> >
>=20
>=20
>=20
>=20
> ------------------------------------
>=20
>
>=20
>

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: How can shift more than 15 bits in 430? - Joe Radomski - Aug 5 11:30:17 2009

looks like correct behavior to me..
the copiler is doing exactly what you are asking it to do..
=C2=A0
if you need a long, you need to declare your constant as a long..
--- On Wed, 8/5/09, =E5=90=B4=E6=8B=A9=E6=B7=B3 wrote:
From: =E5=90=B4=E6=8B=A9=E6=B7=B3
Subject: [msp430] How can shift more than 15 bits in 430?
To: "msp430"
Date: Wednesday, August 5, 2009, 9:51 AM
=C2=A0=20

Hi All:

I am confusing about the shift operation in MSP430, when I shift more than
15 bits to a 32bit number, the complier says "shift count is too large".

what I wrote in C is :

unsigned long AckResult =3D 0; /* AckResult is 32 bit long */

AckResult |=3D (1<<31); /* the compiler warning here */

I have test:

1):
AckResult |=3D (1<<14); /*AckResult is OK:
0b00000000000000000 100000000000000 */
2):
AckResult |=3D (1<<15); /*AckResult is not :
0b11111111111111111 000000000000000 */
3):
when 1<<16 or 17 and so on, AckResult is
0b00000000000000000 000000000000000.

The problem is, how can I set the MSBs of a unsigned long.
Can anyone help me? thanks.

[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: How can shift more than 15 bits in 430? - =?GB2312?B?zuLU8bS+?= - Aug 5 21:17:18 2009

Thanks for all.

MSP430 is a 16 bit microprocessor, so int is 16 bit long, and long is 32
bit.

Finally, 1UL<<31 works much greater fine, which is unsigned long.
[Non-text portions of this message have been removed]

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )