Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, VoroneTZ, AndrewAMD), 834 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Getting 2 ints in one STRING #342200
09/24/10 16:31
09/24/10 16:31
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
Hi,
to decrease bandwidth, I want to put 2 integers in one STRING.
How i can save them in one string without addition information? Just that STRING.
Greets Raz

Re: Getting 2 ints in one STRING [Re: Razoron] #342202
09/24/10 16:50
09/24/10 16:50
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
Code:
str_cpy (s,"");
str_cat (s,format,int1);
str_cat (s,format,int2);


BUT: you can't really reduce bandwidth this way! Only with very small numbers. Example:
A 32bit integer is 4 byte, no matter how big the number is (up to it's maximum) - but if you represent high values as string and not as binary, it needs way more bytes. For example the value 2147483647 needs already 10 byte (instead of 4)!

With 10 bytes (binary), you could store two long and one short integer(s), or 5 short integers etc...

Re: Getting 2 ints in one STRING [Re: wdlmaster] #342207
09/24/10 18:12
09/24/10 18:12
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
Yes, but I don't want to send them in a row.
@ your code:
And how to extract them?
Code:
function send(int i1, int i2)
{
	STRING* s;
	str_cpy(s, "");
	str_cat(s, i1);
	str_cat(s, i2);
	send(s);
}
function recieve(STRING* s)
{
	int i1;
	int i2;
	
	i1 = ??;
	i2 = ??;
}



Re: Getting 2 ints in one STRING [Re: Razoron] #342208
09/24/10 18:14
09/24/10 18:14
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
1) Add a seperating character like !
2) Split the string into the two substrings seperated by the character.
3) Convert both into an integer.
4) ???
5) Profit


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Getting 2 ints in one STRING [Re: Razoron] #342209
09/24/10 18:20
09/24/10 18:20
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
You must use a seperator for the two numbers. Then, use str_stri to get the position of the seperator and a combination of str_clip and str_trunc to "extract" the two values...

Re: Getting 2 ints in one STRING [Re: wdlmaster] #342248
09/25/10 16:10
09/25/10 16:10
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: wdlmaster
You must use a seperator for the two numbers. Then, use str_stri to get the position of the seperator and a combination of str_clip and str_trunc to "extract" the two values...
You don't always need a seperator if you know the length of the integer you're sending

If you're always sending the same length integer, just use str_clip() and str_trunc() to and extract the length you need

If you're changing the length of the integer, just concatenate that into the string


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1