# Label - Expression to conditionally format Hex value

**URL:** <https://forum.inductiveautomation.com/t/label-expression-to-conditionally-format-hex-value/61621>\
**Category:** Ignition\
**Created:** [July 7, 2022, 12:03pm UTC](https://forum.inductiveautomation.com/t/label-expression-to-conditionally-format-hex-value/61621 "2022-07-07T12:03:08Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 7, 2022, 6:02pm UTC](https://forum.inductiveautomation.com/t/label-expression-to-conditionally-format-hex-value/61621/2 "2022-07-07T18:02:56Z")

</div>

This expression will do the trick:

```auto
stringFormat('%02X:%02X',
    ({KasaTMMC/Final4/F4-TL/P1_S001A} >> 8), 
    ({KasaTMMC/Final4/F4-TL/P1_S001A} & 255)
)

```

An explanation of how this works.

1. The `stringFormat` expression accepts format strings which utilizes the Java String Format Syntax, found [here](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter.html). Esentially, this string is saying it will take 2 arguments and format them both as a Hexadecimal Integer with zero padding to a width of 2 characters.

2. This: `{tag} >> 8` performs a right bit shift to the value of tag 8 bits to the right. It helps to think of the numbers in binary. In this instance the binary value would be `0b0000 0111 0000 0111`, following the bit shift the resultant value is `0b0000 0000 0000 0111`.

3. This: `{tag} & 255` performs a bitwise AND operation between the value of tag and 255. Again it helps to think of the numbers in binary. In this instance:  
`0b0000 0111 0000 0111 & 0b0000 0000 1111 1111 = 0b0000 0000 0000 0111`

The resultant string will be `07:07`

---

_[View the full topic](https://forum.inductiveautomation.com/t/label-expression-to-conditionally-format-hex-value/61621)._
