PDA

View Full Version : calculate var Byte's and var Word's



Pedro Pinto
- 19th October 2005, 23:29
Hello All

I need to calculate this example:

varWord = (varByteA*365) + (varByteB*30) + (varByteC/2) + varByteD

The PIC calculate always varWord = 0

How can I write this, or must I before calculate copy the var's byte's in word's, like so

varWordA = varByteA:varWordB = varByteB:varWordC = varByteC:varWordD = varByteD

varWord = (varWordA*365) + (varWordB*30) + (varWordBC/2) + varWordD



Thank for any help

Best Regards

Pedro

BertMan
- 20th October 2005, 00:03
If varByteC is not a multiple of 2, then the result is a floating point, which pbp doesnt support. Also, your word result can be no higher than 65535.

Pedro Pinto
- 22nd October 2005, 20:27
Hi,

what I mean is:

c var byte
b var byte
a var word

c=12
b=34

a=c*b

Is this correct, or must the var a and b be word var

Thanks

Pedro

Pedro Pinto
- 24th October 2005, 11:28
Hi,

sorry,

Is this correct, or must the var b and c be word var?

Regards

Pedro

Melanie
- 24th October 2005, 17:19
Only variables whose content is likely to exceed 8 bits need to be WORDS.

In your example 'a' MUST be a WORD, 'b' and 'c' need not be.

Pedro Pinto
- 31st October 2005, 09:29
Thank You Melany

Regards

Pedro