Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > multiplication ***int32

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



multiplication ***int32
Moderator:
RKRM

Post Reply
Follow this topic



multiplication ***int32

gopal posted on 23 Jul 2012 11:49 PM PST
Member
6 Forum Posts

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;

 

}




Re: multiplication ***int32

SpiderKenny posted on 23 Jul 2012 02:38 AM PST
Top Contributor
83 Forum Posts

  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;



Re: multiplication ***int32

danaaknight posted on 23 Jul 2012 03:22 AM PST
Top Contributor
1773 Forum Posts

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 or 54321
    • 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 or 0XDEAD
    • if a number begins with 0 and is followed by digits from 0 to 7, it is interpreted as an octal (base 8) constant, like 07 (which is the same as 7) or 0111 (which is NOT the same as 111)
  • integer constants in any of the three bases may be followed by an 'l' or 'L' to indicate a long constant, like 17l or 0xFfL
  • in ANSI C, an integer constant may be followed by:
    • a 'u' or 'U' to indicate an unsigned constant, like 33u
    • a 'ul' or 'UL' to indicate an unsigned long constant, like 32767ul
  • an integer constant takes on the minimum type necessary to be accurately represented, (possibly) starting as int and increasing from long to unsigned 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 than int but may have fewer bytes than long)
  • 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 a long 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.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20