In C# short can be converted to byteArray like this
public void WriteShort(short value)
{
WriteBytes(flip(BitConverter.GetBytes(value)));
}
I want to implement this in C or Objective-C
In C# short can be converted to byteArray like this
public void WriteShort(short value)
{
WriteBytes(flip(BitConverter.GetBytes(value)));
}
I want to implement this in C or Objective-C
This is a good case for the union datatype. Assuming a short is always the same size...
union
{
short s;
unsigned char bytes[2];
}u;
In C (considering short is 2 bytes), you could use this:
char* short_to_byteArr (short value)
{
static char byte_arr[] = {};
byte_arr[0] = value & 0x00FF;
byte_arr[1] = (value>>8) & 0x00FF;
return byte_arr;
}