![]() |
Forum Index : Microcontroller and PC projects : AND, NOT, OR, etc.
Author | Message | ||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Having a senior moment. Regardless of the current bit state a=a or 1 Will set the bit but what's the short version of: if a and 1 then a=a xor 1 Pretty sure that in other dialects it's: a=a and not 1 ![]() Edited 2022-12-09 17:39 by Tinine |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5089 |
I understand you are manipulating one bit in integer a. Your second line (the requested functionality) will check the bit. If it is zero, nothing happens When the bit is one it will XOR the variable with that bit (in essence putting it to zero). The outcome is always this particular bit set to zero. So the AND with the negated bit is the correct answer. When a is a boolean, then the shortest solution is: a=0 PicomiteVGA PETSCII ROBOTS |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Example: I am expecting a=254 a=255 a=a and not 1 'just want to reset b0 print a The result is zero |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
a=a and INV 1 |
||||
IanRogers![]() Senior Member ![]() Joined: 09/12/2022 Location: United KingdomPosts: 151 |
If you and with 254 you will preserve the rest of 'a' but reset b0 a = a and 254 I'd give my left arm to be ambidextrous |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
![]() That's QB64 @matherp: That works! Cheers ![]() Not in my DOS version though but it's not the latest. Craig |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
I implemented INV in the CMM2 and have added it to most of my ports. It is the exact equivalent of the C ~ operator which is the standard way of clearing bits To set bit n assuming numbering from 0 a |= (1<<n) to clear bit n a &= ~(1<<n) |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Sure, but what I like to do is: const actuator_1 = &h01 const actuator_2 = &h02 outputs = outputs or actuator_1 outputs = outputs and inv actuator_2 Then I update the DOUTs using the PORT command. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |