Anonymous
Not applicable
Jul 23, 2012
01:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 23, 2012
01:49 AM
hai,
i couldn't acquire a uint32 multiplication with the following code (psoc creator), it calculates wrongly some value. whats my mistake.
#include
<device.h>
uint32
ball;
void
main()
{
ball=4*24*3600;
}
Labels
- Labels:
-
PSoC 3
2 Replies
Jul 23, 2012
04:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 23, 2012
04:38 AM
The compiler by deafault will treat the constants as 'int' and then do a basic 'integer' multiplication, storing the result into the uint32.
You need to tell the compiler how to treat the constants, something like using an integer suffix like this:
ball = 4ul x 24ul x 3200ul;
Jul 23, 2012
05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 23, 2012
05:22 AM
I learned something from this post, reference material -
Integer constants
- Integer constants can be one of the different bases:
- a number starting with a digit from 1 to 9 followed only by digits from 0 to 9 is a decimal (base 10) constant, like
1
or54321
- if a number begins with '0x' or '0X' and is followed by digits from 0 to 9 and letters from a to f or from A to F, it is interpreted as a hexadecimal (base 16) constant, like
0xbeef
or0XDEAD
- if a number begins with 0 and is followed by digits from 0 to 7, it is interpreted as an octal (base 😎 constant, like
07
(which is the same as7
) or0111
(which is NOT the same as111
)
- a number starting with a digit from 1 to 9 followed only by digits from 0 to 9 is a decimal (base 10) constant, like
- integer constants in any of the three bases may be followed by an 'l' or 'L' to indicate a
long
constant, like17l
or0xFfL
- in ANSI C, an integer constant may be followed by:
- a 'u' or 'U' to indicate an
unsigned
constant, like33u
- a 'ul' or 'UL' to indicate an
unsigned long
constant, like32767ul
- a 'u' or 'U' to indicate an
- an integer constant takes on the minimum type necessary to be accurately represented, (possibly) starting as
int
and increasing fromlong
tounsigned long
- octal and hexadecimal constants, and (in ANSI C) constants ending with a 'u' or 'U' may also be
unsigned
(which can hold larger values thanint
but may have fewer bytes thanlong
)
- octal and hexadecimal constants, and (in ANSI C) constants ending with a 'u' or 'U' may also be
- in ANSI C, 0 is always
unsigned
(perhaps to reduce ambiguity on machines with one's complement arithmetic) - as an example, if an
int
is 16 bits wide and along
is 32 bits wide, the following ranges would apply:Range Decimal Octal/Hexadecimal 0 unsigned unsigned 1-32767 int int 32768-65535 long unsigned 65536-2147483647 long long 2147483648-429497295 unsigned long unsigned long 429497296-? ??? ???
Regards, Dana.