change a bit in a variable ?
Moderator: troed
change a bit in a variable ?
In STOS there is a function "BCLR" which can clear a bit (or BSET set a bit) in a variable.. however, hisoft basic doesn't seem to have such a function I could convert the number to a string and use MID$ and convert back to a number, but that seems a bit shitty.. does anyone know of any better ways to manipulate bits in variables ?
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
Re: change a bit in a variable ?
In case that Hisoft Basic doesn't support logical operations (AND, XOR), that could be pretty tricky. If it does, then it's easy:
<input> XOR 01000000 <--- flips the 6th bit
<input> AND 01000000 <--- clears the 6th bit
<input> OR 01000000 <--- sets the 6th bit
<input> XOR 01000000 <--- flips the 6th bit
<input> AND 01000000 <--- clears the 6th bit
<input> OR 01000000 <--- sets the 6th bit
Re: change a bit in a variable ?
Interesting..
I can't see how AND wousod clear a bit though.. As if bit zero was 0 on the input, ANDed with zero, the output would be zero. In fact it would clear all bits other than the bit which is set ?
NAND. Would make sense I think. As a high on bit 7 would result in a zero ?
I can't see how AND wousod clear a bit though.. As if bit zero was 0 on the input, ANDed with zero, the output would be zero. In fact it would clear all bits other than the bit which is set ?
NAND. Would make sense I think. As a high on bit 7 would result in a zero ?
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
Re: change a bit in a variable ?
Oops, you are right.
It should have been: <input> AND 10111111 <--- clears the 6th bit
Too hot!
It should have been: <input> AND 10111111 <--- clears the 6th bit
Too hot!
Re: change a bit in a variable ?
Awesome thanks. I think logic operations are in hisoft, will check it out when I get home later.
Yeah not looking forward to the pending heatwave here over the next few days!
Yeah not looking forward to the pending heatwave here over the next few days!
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
Re: change a bit in a variable ?
It's pretty common in C...
Set bit 3 (0 based index, so bit 3 is 4th bit):
a|=(1<<3)
Clear bit 3:
a&=~(1<<3)
<< - shift left
| - bitwise OR
& - bitwise AND
~ - bitwise NOT
Unfortunately Spectrum BASIC doesn't have bitwise operators, it only has logical ones I'm unsure if in HiSoft BASIC it is any different.
Set bit 3 (0 based index, so bit 3 is 4th bit):
a|=(1<<3)
Clear bit 3:
a&=~(1<<3)
<< - shift left
| - bitwise OR
& - bitwise AND
~ - bitwise NOT
Unfortunately Spectrum BASIC doesn't have bitwise operators, it only has logical ones I'm unsure if in HiSoft BASIC it is any different.
Re: change a bit in a variable ?
https://www.exxosforum.co.uk/atari/ All my hardware guides - mods - games - STOS
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.
https://www.exxosforum.co.uk/atari/store2/ - All my hardware mods for sale - Please help support by making a purchase.
viewtopic.php?f=17&t=1585 Have you done the Mandatory Fixes ?
Just because a lot of people agree on something, doesn't make it a fact. ~exxos ~
People should find solutions to problems, not find problems with solutions.