• Please review our updated Terms and Rules here

the horrors of quickbasic... need help with simple C routine

By the way, doesn't the ASCII method need to be done as follows:

IP: X.Y.Z.W

str1 = str$(X * 256 * 256 * 128 )
str2 = str$(Y * 256 * 256 + Z * 256 + W)
str_total = ascii_add(str1,str1,str2)

since you could only handle integers up to +2.1 billion at a time?

If the IRC server would accept the IP number as a hexadecimal number, it would be much more simple...
 
By the way, doesn't the ASCII method need to be done as follows:

IP: X.Y.Z.W

str1 = str$(X * 256 * 256 * 128 )
str2 = str$(Y * 256 * 256 + Z * 256 + W)
str_total = ascii_add(str1,str1,str2)

since you could only handle integers up to +2.1 billion at a time?

If the IRC server would accept the IP number as a hexadecimal number, it would be much more simple...

well it's not that i have to come up with the number, it's that i had to decode it back to X.Y.Z.W (although i would if i ever add DCC send support in addition to receive, which is already done and working)

i think i'm going to post the client here in a little bit if people want to try it. it is really finished for now. i am going to add a server list and selection box so you dont always have to manually type an IP, and then i'll upload it.

in my testing, it works awesomely on any 286+ machine... it does work on 8088 but screen updates are a bit sluggish. still useable though.
 
Last edited:
Err, you're trying to convert 4294967295 to 255.255.255.255, not the other way around? In that case, doesn't QBasic have bitwise AND and OR operators just like old Microsoft Basic?

Edit: Ahem, you receive "4294967295" as a string, and of course you can't apply VAL onto it because it is too large to represent as an integer. Then you probably would need ASCII subtraction, starting with subtracting "2147483648" from the incoming string, and output four groups of numbers based on if you were able to subtract the whole value or not. Interesting exercise, maybe I'll see if I can do it tomorrow.

Anyway, I wrote a program in Commodore Basic (a.k.a. Microsoft Basic) to convert from an IP number to a long integer. Perhaps it is not fully optimized, but have fun:

Code:
10 INPUT"IP";A$:D=1:I=1:R$="":O$="":OC=0:DIMC(4)
11 C(D)=0:B$=""
12 B$=MID$(A$,I,1):IFI<=LEN(A$)THENI=I+1:IFB$<>"."THENC(D)=C(D)*10+VAL(B$):GOTO12
13 IFD<4THEND=D+1:GOTO11
14 U$=STR$(C(1)*2097152):L$=STR$(C(2)*65536+C(3)*256+C(4))
16 L$=RIGHT$("000000000"+RIGHT$(L$,LEN(L$)-1),10)
17 FORI=LEN(U$)TO1STEP-1:X=VAL(MID$(U$,I,1))*8:C=INT(X/10):L=X-C*10
18 L=L+OC:OC=0:IFL>9THENOC=INT(L/10):L=L-10
19 R$=CHR$(L+48)+R$:OC=OC+C:NEXT
20 R$=RIGHT$("000000000"+R$,10):C=0
21 FORI=LEN(R$)TO1STEP-1:L=VAL(MID$(R$,I,1))+VAL(MID$(L$,I,1))+C
22 C=0:IFL>9THENC=1:L=L-10
23 O$=CHR$(L+48)+O$:NEXT
24 PRINT O$

Some comments: STR$ outputs a leading space when it converts a number to a string, at least on the Commodore. Therefore all the junk with RIGHT$(string,LEN(string)-1) to remove it. The junk with a lot of zeroes is to pad out the strings so they have the maximum length of 10 digits. It is not really required, but instead of a lot of IF statements whichever string is longer than the other, I thought both can be padded.

It would be possible to use ASC instead of VAL in some places, but one would have to subtract the ASCII value for "0" which is 48 in any case, so no gain from there. Needless to say it is dog slow on a 8-bit Commodore. It takes between 50 to 70 clock pulses, i.e. around one second depending on how difficult the IP number is to convert.
 
Last edited:
Back
Top