UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » short into byte array

#1 2007-03-17 12:28 AM

vijraj
Member
Registered: 2006-10-23
Posts: 23

Re: short into byte array

Hi again!

I have to convert byte array into a short and a short into a byte array to send it on the network.How can i do it in c?

Offline

#2 2007-03-17 01:50 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: short into byte array

Something like:

short* i = (short*)bytes_array;
char* array = (char*)&short_i;

There are other ways. All methods are ugly.

Offline

#3 2007-03-17 09:52 PM

vijraj
Member
Registered: 2006-10-23
Posts: 23

Re: short into byte array

Thankyou.That helped a lot.

Offline

  • Index
  • » C
  • » short into byte array

Board footer

Powered by FluxBB