# Sending "unsigned long" over I2C

**URL:** <https://forum.arduino.cc/t/sending-unsigned-long-over-i2c/551517>\
**Category:** General Guidance\
**Created:** [October 17, 2018, 10:24am UTC](https://forum.arduino.cc/t/sending-unsigned-long-over-i2c/551517 "2018-10-17T10:24:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [October 17, 2018, 2:15pm UTC](https://forum.arduino.cc/t/sending-unsigned-long-over-i2c/551517/5 "2018-10-17T14:15:02Z")

</div>

I use a union structure.

```cpp
// create a union to hold the data
union Buffer
{
    long longNumber;
    byte longBytes[4];
};

Buffer buffer;  // create an instance of the union 
buffer.longNumber = 0xaabbccdd;  // assign a value to the long number

```

Now the longBytes array contains the pieces of the long number.  
Send the longBytes array using the write(data, length) function.  
Have an identical union at the receiving end. Read the bytes into the buffer.longBytes array. Now the buffer.longNumber variable holds the long number.

The same method works for float data type. Just replace the long longNumber with  
float floatNumber.

---

_[View the full topic](https://forum.arduino.cc/t/sending-unsigned-long-over-i2c/551517)._
