# HEXADECIMAL string to Binary and Binary to decimal in log-stash using ruby filter

**URL:** https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715
**Category:** Logstash
**Created:** [July 4, 2021, 1:39am UTC](https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715 "2021-07-04T01:39:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kamikaze\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kamikaze_k/32/77246_2.png) [@Kamikaze\_K](https://discuss.elastic.co/u/Kamikaze_K)
#### Post date: [July 4, 2021, 1:39am UTC](https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715/1 "2021-07-04T01:39:25Z")

</div>

I am working with logstash and I am using ruby filter to change HEX to decimal which works fine for one set of data. What I use for this is ;

ruby{  
code =\> "event.set('xxx', event.get('xx').hex)"  
}

I am looking for something similar that will convert HEX to binary then also convert it to decimal after I grok against patterm.The reason I need to do this is because I am picking uneven bits from the hex values e.g

Hex string - "ABC" BINARY - "101010111100"

Then I will use GROK to only pick the first three bits "101" and convert to decimal field which is the value I want , and also for example the next "010" to another field. I am just after help with the two conversions.Not Grok

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 4, 2021, 2:17am UTC](https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715/2 "2021-07-04T02:17:59Z")

</div>

I have answered the question you asked on [StackOverflow](https://stackoverflow.com/questions/68241063/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filte). Please mark it as an answer if it works for you.

---

<div class="post-metadata">

### Author: ![Kamikaze\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kamikaze_k/32/77246_2.png) [@Kamikaze\_K](https://discuss.elastic.co/u/Kamikaze_K)
#### Post date: [July 4, 2021, 2:30am UTC](https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715/3 "2021-07-04T02:30:05Z")

</div>

I am having a look and testing it out. will respond and mark as answered or ask if any issues. really appreciate your help

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 1, 2021, 2:30am UTC](https://discuss.elastic.co/t/hexadecimal-string-to-binary-and-binary-to-decimal-in-log-stash-using-ruby-filter/277715/4 "2021-08-01T02:30:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
