We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › converting byte to integer
Page Index Toggle Pages: 1
converting byte to integer (Read 616 times)
converting byte to integer
Jun 19th, 2008, 1:41am
 
hopefully an extremely simple question.

I want to send data from one computer to another, as type byte[].

is there some simple command I am missing to convert byte data into an integer? or into a float?

thanks.
Re: converting byte to integer
Reply #1 - Jun 19th, 2008, 9:02am
 
Reference > Data > Conversion
http://processing.org/reference/int_.html
http://processing.org/reference/float_.html
Re: converting byte to integer
Reply #2 - Jun 19th, 2008, 6:53pm
 
Well its not quite that simple. I can cast a byte[] array into  an int[] array, but not into a regular int. that returns an error.

In the meantime, i just cast int data as a string and then convert it back on the other side. not very proper, but it works.
Re: converting byte to integer
Reply #3 - Jun 19th, 2008, 8:21pm
 
how much elements does your byte[] array contain?

you can "convert" bytes into an int, assuming your bytes are actually sequences of 4x8=32bits stored in a byte[] array for convenience, but you've got to keep in mind :

1 byte === 8 bits
1 int === 32 bits === 4 bytes

and you have to know in which order the bytes are stored.

is it what you want to do? or did I misunderstood something?
Re: converting byte to integer
Reply #4 - Jun 21st, 2008, 1:06am
 
Hi antiplastik, I ended up doing something very similar to what you described, but in the end I found it was simpler to convert all my int data to a string, send it and split tokens to recover all my variables, and then convert them back into ints.

this is being used as control data for udp multicasting stuff, btw.

thanks.
Page Index Toggle Pages: 1