# Integer math help

**URL:** <https://forum.inductiveautomation.com/t/integer-math-help/15783>\
**Category:** Ignition\
**Created:** [October 26, 2017, 4:34pm UTC](https://forum.inductiveautomation.com/t/integer-math-help/15783 "2017-10-26T16:34:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lujackso](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@lujackso](https://forum.inductiveautomation.com/u/lujackso)\
**Post date:** [October 26, 2017, 4:34pm UTC](https://forum.inductiveautomation.com/t/integer-math-help/15783/1 "2017-10-26T16:34:11Z")

</div>

We are trying to set the date and time to a device over Modbus. The spec for the device seems easy, just not sure if ignition has the math to do it. You just set a few registers, but here is the problem. On a single register we need to set the first 8 bits to the day and the second 8 bits to the month. Is there a way to do this in ignition?

Thanks

Luke

bits 15 to 8 = month (1 to 12) P3: bits 7 to 0 = day (1 to 31)

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 26, 2017, 4:56pm UTC](https://forum.inductiveautomation.com/t/integer-math-help/15783/2 "2017-10-26T16:56:14Z")

</div>

How about something like this:

```auto
month = 1
day = 30
dataReg = (month<<8)+day
system.tag.write("YourTagPath",dataReg)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 26, 2017, 4:59pm UTC](https://forum.inductiveautomation.com/t/integer-math-help/15783/3 "2017-10-26T16:59:54Z")

</div>

You may need to flip the order around - Modbus is supposed to be big-endian, but word order differs between different devices.

```auto
today = system.date.now()
day = system.date.getDayOfMonth(today)
month = system.date.getMonth(today) + 1

word = (month<<8) | day

system.tag.write("SomeTag", word)

```

---

<div class="post-metadata">

**Author:** ![lujackso](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@lujackso](https://forum.inductiveautomation.com/u/lujackso)\
**Post date:** [October 26, 2017, 7:10pm UTC](https://forum.inductiveautomation.com/t/integer-math-help/15783/4 "2017-10-26T19:10:17Z")

</div>

Thanks, This will get us well on our way.
