[SOLVED] positive values only up to 31Bit???
#1

Hai there...

I have found my problem already and only need some info!

I wanted to calculate the decimal value of IP-Adresses (which is 32 Bit obviously).
But PAWN wiki's and tutorials say, that all PAWN variable types use these 32 for + and - !! (32nd Bit as flag for negative)
This means i can only use 31 Bit of these variables for positive values - values bigger than 2,147,483,648 switch to negative values... So i can never get the right decimal value if it is bigger than that.

Now is there any variable type in PAWN that uses ALL its 32 Bits for positive values? Or any other suggestion?
In the end i need the decimal value of the IP-Adress as a string, to put it into a mySQL-query string...

Thx for ur time
TuNe
(littlefisheys training fun, 85.17.200.135:9800)
Reply
#2

I know, it sucks. Can't you set the mySQL DB to use signed instead of unsigned?
Reply
#3

can you get some more specific?

what would that help with too small PAWN variables?
The mySQL fields ARE able to store these big values - but PAWn vars AREN'T... :S
Reply
#4

Why do you need the decimal value of somebody's ip address. Could you not save the IP as a string and compare them when needed?
Reply
#5

Wierdosport: Because it is easier to store, what is better? An integer or a string?

Quote:
Originally Posted by TuNeFisH
can you get some more specific?

what would that help with too small PAWN variables?
The mySQL fields ARE able to store these big values - but PAWn vars AREN'T... :S
Yes, mySQL is good that way, but seeing as PAWN lacks that %u format, you can't really convert to unsigned. What I mean is, allow mySQL to have negative values (signed), and if you need to get the IP in a real language (like C++, PHP) you can use the %u there.
Reply
#6

Cuz i need to compare them with ranges - and thats kinda difficult with as string
Reply
#7

Ok, so how do you convert the IP as a string to a decimal? (Not saying you're wrong to want it as a decimal, just trying to work through the problem)
Reply
#8

Tunefish, you could explode the IP into 4 segments and convert that into integers. You could check ranges that way. At the most (using IPv4) you would need only 256 bits rather than 2^32.
Reply
#9

Quote:
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Tunefish, you could explode the IP into 4 segments and convert that into integers. You could check ranges that way.
That's what I was working towards, but I didn't know enough about how you turn an IP address into a decimal :P

This may aid with the exploding: https://sampwiki.blast.hk/wiki/Code_Snippets#Split
Reply
#10

nope i cant, cuz the 4 segments have different exponent values...

@ Weirdosport:
Im application developer in my job, so i think i know how to convert ;P
A.B.C.D -> (A * 256^3) + (B * 256^2) + (C * 256^1) + (D * 256^0)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)