# How to convert a HEX value to a char?

**URL:** <https://forum.mikrotik.com/t/how-to-convert-a-hex-value-to-a-char/97913>\
**Category:** Scripting\
**Created:** [May 6, 2016, 6:18am UTC](https://forum.mikrotik.com/t/how-to-convert-a-hex-value-to-a-char/97913 "2016-05-06T06:18:10Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jeroenp](https://forum.mikrotik.com/letter_avatar/jeroenp/32/6_449c533f586939b6e5f246632a46421f.png) [@jeroenp](https://forum.mikrotik.com/u/jeroenp)\
**Post date:** [May 6, 2016, 6:18am UTC](https://forum.mikrotik.com/t/how-to-convert-a-hex-value-to-a-char/97913/1 "2016-05-06T06:18:10Z")

</div>

I’m trying to fill an associative array with mappings from characters to their HEX encoding.

The below fails: it doesn’t like the `("\0".$hexChar)` construct.

So: how do I convert a string containing the characters "", “0” and “1” (where “0” and “1” are dynamically generated) so it parses as “\01”?

```plaintext
:global convert ({});
#:set ($convert->"\00") "\\00"
:set ($convert->"\7F") "\\7F"
:set ($convert->"\81") "\\81"
:local hexChars "01234567890ABCDEF"
:local groupChars "01890ABCDEF"
  :for hexCharsIndex from=0 to=([:len $hexChars] - 1) do={ 
    :local hexChar [:pick $hexChars $hexCharsIndex]
    :set ($convert->("\0".$hexChar)) ("\\0".$hexChar)
  }

```

–jeroen

---

_[View the full topic](https://forum.mikrotik.com/t/how-to-convert-a-hex-value-to-a-char/97913)._
