title: Transfering an int as two bytes on the Arduino
body: <p>I'm sampling at high frequencies and need to transmit the 10-bit ADC value via UART out of my Arduino.</p>
  
  <p>By default, it uses a byte per character. So if doing an analogRead would yield the value of "612", it would send via UART "6" as one byte, "1" as one byte, "2" as one byte, and the line terminator as the last byte.</p>
  
  <p>Given that my sampling rate is truncated by this communication, it's important that it's as efficient and <strong>uniform</strong> as possible, so I'm trying to force it to use two bytes to transmit that data, doesn't matter what the data actual is (by default it would use three bytes to transmit "23", four bytes to transmit "883" and five bytes to transmit "1001"). </p>
  
  <p>Currently, I'm doing something like this, which is the best way I've found:</p>
  
  <pre><code>int a = 600; //Just an example
  char high = (char)highByte(a);
  char low = (char)lowByte(a);
  Serial.print(high);
  Serial.println(low);
  </code></pre>
  
  <p>Currently this uses three bytes (including \n) regardless of the value. Is there an even more efficient method?</p>
  
  <p>Just printing it with something like</p>
  
  <pre><code>Serial.print(foo, BIN);
  </code></pre>
  
  <p>Doesn't work at all. It actually uses one byte per every single bit of the binary representation of foo, which is quite silly.</p>