PDA

View Full Version : Setting / resetting a variable bit within a byte



Charles Linquis
- 8th February 2008, 03:20
To clear bit 3 in Variable1, I find that

If Y = 3 -


The statement:

Variable1.Y = 0 does not compile, while

Variable1.0[Y] = 0

DOES compile - but does it work properly? I don't have any
hardware to test it on tonight. Even if it does work, is there
a better way?

KVLV
- 8th February 2008, 04:08
do it this way
if y=3 then
variable.3=0

...

Charles Linquis
- 8th February 2008, 04:34
To do it your way, if I had a WORD variable, I would need 16 IF..THENs or 16 CASE statements. There has to be a better way.

Ioannis
- 8th February 2008, 06:28
Hi Charles. This .0[x] thing is old news but works very well. It's an undocumended feature.

I do not think there is a more compact way than this. Why don't you like it?

Ioannis

Charles Linquis
- 8th February 2008, 13:31
It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

Thanks!

skimask
- 8th February 2008, 13:39
It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

Thanks!

I'm sure you've seen this thread by Melanie right?

http://www.picbasic.co.uk/forum/showthread.php?t=544

A lifesaver thread for sure...

Ioannis
- 9th February 2008, 11:14
It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

Thanks!

If you search the forum with the right tool it will reveal the secret!

look at this:
http://www.google.com/custom?q=%22.0%5B%22&cof=S%3Ahttp%3A%2F%2Fwww.picbasic.co.uk%2Fforum%3B AH%3Aleft%3BLH%3A37%3BL%3Ahttp%3A%2F%2Fwww.crownhi ll.co.uk%2Flogo.gif%3BLW%3A174%3BAWFID%3Af08c2ab0d 3333e22%3B&domains=picbasic.co.uk&sitesearch=picbasic.co.uk

And from now on you may use the:

http://www.picbasic.co.uk/forum/showthread.php?t=4751

to search the forum for sort terms like ".0["

Ioannis

Charles Linquis
- 9th February 2008, 16:32
I vaguely remembered seeing the solution awhile back, but forgot the details. I do something similar in my own "monitor" program in Code Examples, so I should have known better.

Melanie doesn't seem to answer as many questions as she used to.

Melanie, are you there? Is your lack of posts the result of being disgusted with us, or are you busy?

Ioannis
- 9th February 2008, 18:38
I vote for 2.

Ioannis