title: Get byte representation of int, using only 3 bytes
body: <p>What's a nice, readable way of getting the byte representation (i.e. a <code>byte[]</code>) of an <code>int</code>, but only using 3 bytes (instead of 4)? I'm using Hadoop/Hbase and their <code>Bytes</code> utility class has a <code>toBytes</code> function but that will always use 4 bytes.</p>
  
  <p>Ideally, I'd also like a nice, readable way of encoding to as few bytes as possible, i.e. if the number fits in one byte then only use one.</p>
  
  <p>Please note that I'm storing this in a <code>byte[]</code>, so I know the length of the array and thus variable length encoding is not necessary. This is about finding an elegant way to do the cast.</p>