You will not be able to post if you are still using Microsoft email addresses such as Hotmail etc
See here for more information viewtopic.php?f=20&t=7296
BOOKMARK THIS PAGE !
https://www.exxosforum.co.uk:8085/IP_CHECK/
You can unban yourself if needed. It also sends me reports to investigate the ban.
DO NOT USE MOBILE / CGNAT DEVICES WHERE THE IP CHANGES CONSTANTLY!
At this time, it is unfortunately not possible to whitelist users when your IP changes constantly.
You may inadvertently get banned because a previous attack may have used the IP you are now on.
So I suggest people only use fixed IP address devices until I can think of a solution for this problem!

change a bit in a variable ?

News,announcements,programming,fixes,game patches & discussions.
User avatar
exxos
Site Admin
Site Admin
Posts: 27907
Joined: 16 Aug 2017 23:19
Location: UK

change a bit in a variable ?

Post by exxos »

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 :roll: 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 ?
mikro
Posts: 810
Joined: 28 Aug 2017 23:22
Location: Kosice, Slovakia

Re: change a bit in a variable ?

Post by mikro »

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
User avatar
exxos
Site Admin
Site Admin
Posts: 27907
Joined: 16 Aug 2017 23:19
Location: UK

Re: change a bit in a variable ?

Post by exxos »

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 ?
mikro
Posts: 810
Joined: 28 Aug 2017 23:22
Location: Kosice, Slovakia

Re: change a bit in a variable ?

Post by mikro »

Oops, you are right.

It should have been: <input> AND 10111111 <--- clears the 6th bit

Too hot! :)
User avatar
exxos
Site Admin
Site Admin
Posts: 27907
Joined: 16 Aug 2017 23:19
Location: UK

Re: change a bit in a variable ?

Post by exxos »

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!
tzok
Posts: 338
Joined: 30 Dec 2017 14:27

Re: change a bit in a variable ?

Post by tzok »

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.
User avatar
exxos
Site Admin
Site Admin
Posts: 27907
Joined: 16 Aug 2017 23:19
Location: UK

Re: change a bit in a variable ?

Post by exxos »

1.jpg
You do not have the required permissions to view the files attached to this post.

Return to “SOFTWARE PROGRAMMING & DISCUSSION”

Who is online

Users browsing this forum: CCBot and 10 guests