# Hexadecimal to Decimal

**URL:** https://discuss.elastic.co/t/hexadecimal-to-decimal/293361
**Category:** Logstash
**Created:** [January 3, 2022, 3:24pm UTC](https://discuss.elastic.co/t/hexadecimal-to-decimal/293361 "2022-01-03T15:24:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dayajamal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dayajamal/32/94073_2.png) [@dayajamal](https://discuss.elastic.co/u/dayajamal)
#### Post date: [January 3, 2022, 3:24pm UTC](https://discuss.elastic.co/t/hexadecimal-to-decimal/293361/1 "2022-01-03T15:24:08Z")

</div>

Hi, I am trying to convert a field in my log from hexadecimal to decimal.

I tried with the following log:

`2021-07-26T16:49:02.189807+0200 | DEBUG | 910EAB70 | flyscan/core/server.1 | ScanActorTask::handle_message`

Using the following code I try changing the hexa field I called process thread id to decimal:

```auto
    mutate {
        convert => { "[process][thread][id]" => "integer" }
       }
    
    ruby {
        code => "event.set('[process][thread][id]', event.get('[process][thread][id]').to_s.hex)"
      }

```

910EAB70 was transformed to 2320 in Elasticsearch (which is 910 in hexadecimal) knowing that the right answer is 2433657712.

I tried for another log:  
`2021-07-26T16:49:02.185140+0200 | DEBUG | AF788B70 | flyscan/core/server.1 | FlyscanTask::handle_message LOAD_CONFIG`

AF788B70 herewas transformed to 0 in Elasticsearch knowing that the right answer is 2943912816.

What am I missing? Thanks in advance.

---

<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: [January 3, 2022, 5:30pm UTC](https://discuss.elastic.co/t/hexadecimal-to-decimal/293361/2 "2022-01-03T17:30:26Z")

</div>

> [@dayajamal](#):
>
> `convert => { "[process][thread][id]" => "integer" }`

convert calls .to\_i on the string, which by default works in base 10, and "Returns the integer value of leading characters, interpreted as an integer". If you want to parse it as hex you will have to do that in the ruby filter.

---

<div class="post-metadata">

### Author: ![dayajamal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dayajamal/32/94073_2.png) [@dayajamal](https://discuss.elastic.co/u/dayajamal)
#### Post date: [January 4, 2022, 8:16am UTC](https://discuss.elastic.co/t/hexadecimal-to-decimal/293361/3 "2022-01-04T08:16:42Z")

</div>

```auto
    ruby {
        code => '
            hexNum = event.get("[process][thread][id]")
            event.set("decNum", hexNum.to_i(16).to_s(10))
        '
    }
    ruby {
        code => "event.set('[process][thread][id]', event.get('[process][thread][id]').to_s.hex)"
      }

```

Thanks

---

<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: [February 1, 2022, 8:17am UTC](https://discuss.elastic.co/t/hexadecimal-to-decimal/293361/4 "2022-02-01T08:17:06Z")

</div>

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