The Shop > Electronics & IC Programing

STR$

<< < (3/6) > >>

DavidA:
vt,

Turns out that things are much trickier that first thought.

That c$ I,e,  C$=(11111111)  seems to be a 16 byte string.

I ran print len(c$) and discovered this.

Sooooo. it is actually 0101010101010101

and it is not responding well to slicing.

You would think it quite straight forward to extract every second byte,  but oh no.
If I start at byte 8 I get 256  2^8 = 256
But  with    byte 7 I get the same. For some reason it delivers a pair of values. both equal to the even number'

You'll note I say bytes and not bits.  I suspect the whole problem is because c$ is a concatenation of eight other strings. each of these strings (e$ to l$) is either 0 or 1 depending on the state of the port.

I'm going to have to go back to the drawing board and devise a different method.

Woe is me.

Dave :doh:

David Jupp:
In a string, each character is represented by an ASCII code (2 bytes) - if you want to do arithmetic, you'll have to convert to a number first (either the whole string, or the snippets cut from it).  The CAST operator may be helpful.

RussellT:
I haven't tried this because my computer with qbasic on is out in the garage but it seems to me that you'd be better off trying to do without strings.

For example.

Create a couple of variables eg poweroftwo and output and set them to one and  zero respectively.
Create a for/next loop to go around 8 times.
Double the poweroftwo variable each time you go around a loop to give powers of 2.
If the printer port bit is set add the power of two to the output variable - at the end of the loop the output variable should be the decimal value you are seeking.

I hope this helps.

Russell

gerritv:
If you use a shift to feed the bit value into the output variable you will then know for a fact that the output is a consecutive series of bits?

http://www.petesqbsite.com/phpBB3/viewtopic.php?f=1&t=1389

So, shift value left 1 bit, OR value of bit 6 into the low order bit, loop

Output is then an 8 bit value in 16 bits, no lookup table required.

vtsteam:
try


--- Code: ---X=0
FOR i = 16 to 1 step -2
E = VAL(MID$(C$,i,1))
X = X + (E*(2^(8-(i/2))))
NEXT
--- End code ---

let me know if that works.

if that always gives you 0 as an answer we just have to shift one.


ps. I see I had an error in my earlier code -- one too many left parenthesis -- but you probably already figured that out.  :palm:

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version