Convert Int to Byte Array?

hello again,
im working with the fez mini and working on my headtracking project. it connects a wiimote camera (removed and made into an i2c device) the fez mini a xbee.

im looking to transfer 2 integers over a serial line in a way that doesnt use strings (because they are slow). is it possible to do this? seems like it should be.

in winform stuff i can just use the BitConverter object but that doesnt seem to be available in NETMF. previously i was constructing a long string that held all my values but the processing of the string on the receivers side seems to perfom slow. i think its because having to do things like string splits takes too long for the speed i am trying to get it to operate at (think ~10ms between sends). the bytesAvailable queue seems to get backed up as i process.

i was using this


byte[] intBytes = Encoding.UTF8.GetBytes(txtInteger.Text);

but that only takes in a string (i want to use an int like 120 instead of sending “120”)

anybody have any advice? this should be easy, right? what am i not getting? sending numbers should be easier then sending a string…

Utilities.insertIntoArray

im stupid, i didnt have a good understanding what i was doing, my web app programming doesnt deal with bytes directly very often. i was trying to send a couple servo positions (0-180) over serial and i had been sending a longer string that contained the positions (ex “120,80”).

the problem i was having was that the receiver was getting caught up parsing the string so sometimes i would build up a few readings while i was trying to parse the string to 1) determine if it was a valid reading and 2) see what the data was.

i had been looking for a simple way to convert the int to a byte array to send. what i didnt think about was the byte array didnt have to be created like that, i could just do this:

                
tx_data = new byte[]{(byte)x,(byte)y};
UART.Write(tx_data, 0, tx_data.Length);

since i know that the int values of x and y will be between 0 and 180 already (they are output from a math formula that can only reach those values at it max).

thanks for the help gus, getting really close to a demo video, the fez mini is awesome. what library is Utilities.insertIntoArray() in? got a link for more info? (links will help your SEO anyways)