-->
Page 1 of 1

working with Vars, decimal, hex and binary and how to compar

PostPosted: Sat Aug 20, 2016 11:53 am
by Ecoli-557
OK you 8266 Basic Gurus, this noob is fuzzy on how I use decimal, Hex, and binary in a variable.
I am trying to do something really simple but I don't have any success.
If I wanted to see if a variable equals a hex value, how do you do it?
Want to see if pressed which is a var equals hex FF;
- none of these work:
if pressed <> HEX (FF) then print something
if pressed <> HEX ((FF)) then print something
if pressed <> 0xFF then print something
likewise, how do you set a vars value? Say I wanted to equate somevar equal to a hex value of A5?
somevar = 0xA5 doesn't work, somevar = HEX(A5) gives me 7FFFFFFFF
Then, how do you equate a variable to a binary number?
Say I wanted to equate or test a variable to 01010101?


Basically I want to equate any numeric variable to a decimal, hex, or binary value, compare a variable against any of these three.
Apologies if this is listed somewhere but I cannot find it in the docs or by perusing other work on this forum.
This is basic and should be easy??

Re: working with Vars, decimal, hex and binary and how to co

PostPosted: Sat Aug 20, 2016 12:22 pm
by joeygbsn
The hex function converts a decimal value to a hex value. So hex(255) would yield FF. I think this is what is messing you up.

Re: working with Vars, decimal, hex and binary and how to co

PostPosted: Sat Aug 20, 2016 12:47 pm
by Ecoli-557
Thanks joeygbsn for the reply.
I think I have that part down, what I don't know how to do correctly is equate a variable and then compare it against a value.
Pseudo code below:
SomeVar = hex A5
If SomVar <> hexA7 then print something
I tend to work in hex a bit due to my sensor work desires so getting the hex stuff is central to me getting this understood.
How do you equate a var to a hex value, then compare that var against a different hex value?

Re: working with Vars, decimal, hex and binary and how to co

PostPosted: Sat Aug 20, 2016 1:38 pm
by joeygbsn
It should be just as simple as:
Code: Select alllet var = A5
if var = A5 then print something