PDA

View Full Version : Let a variable change from bin to dec.



Roy
- 24th May 2004, 16:02
Hi all !

I tried the attached listning from Rentron.

I tried to do compare a variable decimaltemp with a defined value of 25 and the varable TempC.

The problem is that tempC is a binary and not the uservariable.

I want to set variable decimaltemp = dec (TempC) but have'nt found any function for that.

It is possible to do such function in serout serout2 and lcdout but not to a variable.....?

What am i missing ?

Rentron listning:
http://www.rentron.com/PicBasic/one-wire3.htm

Brgds Roy

d1camero
- 24th May 2004, 20:44
I am not sure I understand, but I will try anyways. Variable "decimaltemp" is a word which contains the ASCII representation of some number (e.g. 25). Is this correct? And you want to compare it to variable "TempC" which has the binary value of the temperature. Correct? If so, you need to convert the ASCII value in var "decimaltemp" to a binary value.

To convert a to digit ASCII word to a binary value, you need to subtract 48 from each byte.

this might work, I am sure others have way of doing it too.

<code>
DecimalTemp var word
BinaryTemp var word

BinaryTemp = (DecimalTemp.highbyte - 48)*10 + (DecimalTemp.lowbyte - 48)
</code>

Don

Roy
- 25th May 2004, 19:57
Your right !
I understand now, its not decimal its of course ascii.

Have not tested yet, but its make sense.

Thanks Don !

Brgds Roy