# How to convert hex value into decimal in painless language

**URL:** https://discuss.elastic.co/t/how-to-convert-hex-value-into-decimal-in-painless-language/364554
**Category:** Elasticsearch
**Tags:** painless
**Created:** [August 7, 2024, 6:33pm UTC](https://discuss.elastic.co/t/how-to-convert-hex-value-into-decimal-in-painless-language/364554 "2024-08-07T18:33:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nabeel1](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@nabeel1](https://discuss.elastic.co/u/nabeel1)
#### Post date: [August 7, 2024, 6:33pm UTC](https://discuss.elastic.co/t/how-to-convert-hex-value-into-decimal-in-painless-language/364554/1 "2024-08-07T18:33:09Z")

</div>

Can anyone inform the syntax to convert a value from hex to decimal for a bucket index ..  
e.g. i want to convert this substring which is the IP in hex to a IP in decimal .. so, from string need to convert to hex and then int?

'IP': bucket.key[2].substring(0,2)+"."+bucket.key[2].substring(3,5)+"."+bucket.key[2].substring(6,8)+"."+bucket.key[2].substring(9,11)

---

<div class="post-metadata">

### Author: ![nabeel1](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@nabeel1](https://discuss.elastic.co/u/nabeel1)
#### Post date: [August 7, 2024, 6:34pm UTC](https://discuss.elastic.co/t/how-to-convert-hex-value-into-decimal-in-painless-language/364554/2 "2024-08-07T18:34:17Z")

</div>

'IP': bucket.key[2].substring(0,11)
