The Shop > Electronics & IC Programing
STR$
DavidA:
Here is a chance to scrape the rust of your memory cells.
For ex- GWBASIC programmers.
I have a small problem.
I created a little program that reads bit six of the printer ports status port.
All it does is pol the status of the port A=(&h379).
It does this eight times and creates a series of Strings (E$ to L$) and concatenates the eight strings to create one string called C$
So far so good.
So I finish up with something like C$=(11111111) if all the hits were + or c$=(00000000) if they were all naughts.
Now for the fun bit.
As I am wanting to finish up with the decimal value of this string (from 0 to 255) I have sliced out each digit and compared it with a table holding the values. 128, 64,32,16,8,4,2,1.
Here is the problem.
If I use use, say, E=VAL(mid$(c$,1,1)) to get the first digit then when I get a wrong answer. I always get E=0. Not e=128 as the table says.
Now, I have worked out what is happening, but not why.
If I change the line to E=VAL(mid$(c$,2,1)) theoretically extracting the second bit, which one would expect to be 64, then it works. It gives me 128.
I have to go up in stages of two. So the seventh bit becomes K=VAL(mid$(C$,14,1)). Up to the last part (bit 8) which needs to be read as L=VAL(mid$(c$,8,1)) or it gives back L=0 every time.
I suspect that it is something to do wit an 'invisible' sign bit in front of each bit. So I see 8 bits but there are actually 16.
What is the proper procedure for using MID$ ?
Dave.
vtsteam:
Dave,
hard to say without seeing the actual code. Did you first check that MID$() and VAL is working for you the way you guess it is by something like:
C$= "12345678"
FOR i = 1 to 8
PRINT MID$(C$,i,1)
PRINT VAL(MID$(C$,i,1))
NEXT
--I'm going to have to dig out my old laptop with win98 for this!!
RussellT:
I've not checked on this but is this a problem with bytes and integers - both can use a single byte but encoding is different?
Russell
vtsteam:
Integers in the old interpreted MS basics were 2 bytes and ranged from -32K to 32K.
awemawson:
In that basic version is there a 'Mask' function. Years back when I was doing bit manipulation of bytes I'd mask to the bit I wanted, logical 'and'. them and jump on none zero result, or alternatively add the byte to itself repeatedly testing the sign bit as this effectively does a serial left shift of bits into the sign position.
Navigation
[0] Message Index
[#] Next page
Go to full version