user7250: How do you convert an unsigned long to a uint8_t array? I am interested in sending an unsigned long integer from an ATTiny85 to an Arduino Uno via I2C. The issue is with TinyWireS.Send() which can only send a var of type uint8_t. I believe the solution would be to use TinyWireS.Send() in an array?

user1585: This might not be politically correct code, but it is pretty simple to just cast a pointer to uint8_t like this:
long data = 5;
uint8_t *rx = (uint8_t*) &data;

You can still use array subscripts even though its a pointer, and you can pass it to a function like an array. Just don't go past rx[3].
Alternately, you could also make a union like this:
union{ long data; uint8_t bytes[4]; } convert;
convert.data = 5;

And then use convert.bytes as your array to send.

7250: <p>How do you convert an unsigned long to a <code>uint8_t</code> array? I am interested in sending an unsigned long integer from an ATTiny85 to an Arduino Uno via I2C. The issue is with <code>TinyWireS.Send()</code> which can only send a var of type <code>uint8_t</code>. I believe the solution would be to use <code>TinyWireS.Send()</code> in an array?</p>
 1585: <p>This might not be politically correct code, but it is pretty simple to just cast a pointer to uint8_t like this:</p>

<pre><code>long data = 5;
uint8_t *rx = (uint8_t*) &amp;data;
</code></pre>

<p>You can still use array subscripts even though its a pointer, and you can pass it to a function like an array. Just don't go past <code>rx[3]</code>.</p>

<p>Alternately, you could also make a union like this:</p>

<pre><code>union{ long data; uint8_t bytes[4]; } convert;
convert.data = 5;
</code></pre>

<p>And then use <code>convert.bytes</code> as your array to send.</p>
