How to load integer into uint8_t array?

I am trying a comms library in which you put data into an uint8_t array, execute a send command, and it comes out the other end in an unint8_t array.

I need to transmit integers greater than 256.

To test my casting I wrote the following sketch:

uint8_t InBuffer[] = {"300"};
int x = 999;

void setup()  
{
  delay(2000);
  Serial.begin(19200);  
  itoa(x, (char*)InBuffer, 10);  
  Serial.println((char*)InBuffer);
  Serial.println(2 * atoi((char*)InBuffer));
  int y = atoi((char*)InBuffer);
  Serial.println(y);  
}

void loop()
{
  //Serial.println("Looping..");
  delay(1000);
}

While this code seems to work OK I question the seemingly verbose and inefficient " int y = atoi((char*)InBuffer);" and " itoa(x, (char*)InBuffer, 10);" each with their double conversions.

Is there a more eloquent and efficient way to put and extract a large integer from an uint8_t array?

Is there a more eloquent and efficient way to put and extract a large integer from an uint8_t array?

Of course. An int is two bytes. You can easily extract the highByte() or lowByte().

Given two bytes, the int is recreated by shifting the high byte 8 places to the left and adding the low byte.

if the data is actually an int spread between the two uint8_t values then simply cast its pointer, not the data.

uint8_t u_Data[2];

uint16_t u_Int = *( uint16_t* ) u_Data;

Thanks guys for the quick response. I felt there had to be a better way.

@ pYro_65: I will have to study up on casting of pointers as the " ( uint16_t ) u_Data; " is beyond my past limited pointer usage! (I didn't know you could cast a pointer).