Test bit of byte in QBasic 4.5

Status
Not open for further replies.

Sputnik

Full Member level 3
Joined
Oct 19, 2004
Messages
150
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,298
Location
South Africa
Activity points
1,667
I've been trying to accomplish this for a few days, in fact, I don't even know why I bother asking for help cause I just won't finish the project anyway, but maybe this one will work out.

I need to test a bit of a byte in QBasic so that I may know whether or not to add a specific value or not (to set the bit) so that I don't get unexpected results, it's for the parallel port control register.

Thanks
Sputnik :idea:
 

This should work:

if byte and xxx then

xxx can be any bit position like 1 2 4 8 16 for a single bit ...

best regards
 

I was just about to delete my topic as I have just figured it out, this is how I did it:

Code:
CLS

INPUT "Enter port address: ", port

byte = INP(port)
value = 128

FOR i = 0 TO 7
LOCATE (11 - (i + 1)), 1: PRINT i
LOCATE 1, 1: PRINT "Bit | Place Value | Bit Value"
LOCATE i + 3, 10: PRINT value
IF byte >= value THEN
bit(i) = 1
byte = byte - value
ELSEIF byte < value THEN
bit(i) = 0
END IF
LOCATE i + 3, 24: PRINT bit(i)
value = value / 2
NEXT i

I know it's probably messy and could be more efficient but, if it works, leave it.

But thanks anyway,
Sputnik :idea:
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…