On 10/26/22 4:33 PM, John R. Hogerhuis wrote:
Anyone know how to compute a 16-bit integer address without overflow?

Trying to get the address of a string H$ into a variable C that I can PEEK. The first byte of a string object is the length. It's followed by a pointer to the string

10 DEFINTA-F
20 H$="0123456789ABCDEF": D=VARPTR(H$)+1:C=PEEK(D)+256*PEEK(D+1)

You have to make it a negative number by subtracting it from 65536:

20 H$="0123456789ABCDEF": D=VARPTR(H$)+1:IFPEEK(D+1)>127THENC=65536-256*PEEK(D+1)-PEEK(D)ELSEC=PEEK(D)+256*PEEK(D+1)



No workey... overflow error.

What is happening is that PEEK(D+1) is 128. 256 * 128 = 32768 which is too big to be stored in C% (a 16-bit signed integer)

So given a number 0-65535 is there a good way in BASIC to get the 16-bit signed value -32768..32767?

FWIW, AND and NOT only work on signed 16-bit values, not > 32767 positive values.

-- John.

Reply via email to