# Big Integers (larger than long)

**URL:** <https://forum.kx.com/t/big-integers-larger-than-long/12127>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [April 8, 2021, 11:50am UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127 "2021-04-08T11:50:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandy\_bradley](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sandy\_bradley](https://forum.kx.com/u/sandy_bradley)\
**Post date:** [April 8, 2021, 11:50am UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127/1 "2021-04-08T11:50:00Z")

</div>

Anyone know how to handle numbers larger than long in kdb+?

I need to handle numbers with 20+ digits in kdb+. It seems there is no inbuilt data types for this, other than to store the number as a string or hex.

Does anyone know any KDB+ libraries to do hex math i.e. addition, multiplication on hex / binary numbers?

Alternatively, any C libraries to use?

Best,

Alexander

---

<div class="post-metadata">

**Author:** ![dotsch1](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@dotsch1](https://forum.kx.com/u/dotsch1)\
**Post date:** [April 8, 2021, 12:21pm UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127/2 "2021-04-08T12:21:00Z")

</div>

Hi Alexander,

I think \_\_int128 is available in GCC as an extension. I would store those 16byte ints as guids&nbsp;on the kdb side and develop the necessary&nbsp;functions in C.  
This is interesting, I might come back to you with&nbsp;some prototype code today/tomorrow.

Regards,

Andras

---

<div class="post-metadata">

**Author:** ![sandy\_bradley](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sandy\_bradley](https://forum.kx.com/u/sandy_bradley)\
**Post date:** [April 8, 2021, 12:58pm UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127/3 "2021-04-08T12:58:00Z")

</div>

Thanks Andras,

I found a couple of C libraries that could be modified to integrate K structs:

https://github.com/SzigetiJ/biguint

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjwwrGww-7vAhUFi1wKHQaSD\_AQFjANegQIFRAE&url=https%3A%2F%2Fwww3.cs.stonybrook.edu%2F~skiena%2F392%2Fprograms%2Fbignum.c&usg=AOvVaw3v2FJGLxIzrFT2uUzh5\_C-

---

<div class="post-metadata">

**Author:** ![sandy\_bradley](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sandy\_bradley](https://forum.kx.com/u/sandy_bradley)\
**Post date:** [April 11, 2021, 3:01pm UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127/4 "2021-04-11T15:01:00Z")

</div>

To anyone looking for Big Integer arithmetic in future, I made a C library to integrate into kdb at:

https://github.com/manifoldfinance/qBigInt

---

<div class="post-metadata">

**Author:** ![dotsch1](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@dotsch1](https://forum.kx.com/u/dotsch1)\
**Post date:** [April 11, 2021, 4:03pm UTC](https://forum.kx.com/t/big-integers-larger-than-long/12127/5 "2021-04-11T16:03:00Z")

</div>

Another option, GCC’s \_\_int128 extension as guid:  
https://github.com/adotsch/c-extensions-to-q
