CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

can I multiply a Hex value with a decimal?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Nick
Guest







can I multiply a Hex value with a decimal?
PostPosted: Sat Jan 22, 2005 6:14 pm     Reply with quote

It complies, but that doesnt mean it will work ;-)

is this a valid statment?

int x =3;

If ( x < (0x9E*(0.05)) )

{ }
Ttelmah
Guest







Re: can I multiply a Hex value with a decimal?
PostPosted: Sun Jan 23, 2005 4:00 am     Reply with quote

Nick wrote:
It complies, but that doesnt mean it will work ;-)

is this a valid statment?

int x =3;

If ( x < (0x9E*(0.05)) )

{ }

It's sort of a valid statement, but may not do what you want. Assuming you want to compare 'x' with the integer value of the result, use a cast like:
Code:

If (  x < (int8)(0x9E*0.05))

The compiler will in fact solve the foating point 'sum', since it only involves constants, at compile time, to generate the constant '7', and then carry out an integer comparison on this. If the comparison contains a variable, this will be solved at run time instead.
Without the cast, you are entering a 'black area', where the compiler can get confused about the types involved....
The result on the version without the cast, varies with compiler version. I tried two different versions, and one completely 'lost' the statement (look at the assembler). The cast is safer.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group