# Long Type hex ERROR

**URL:** <https://discuss.kotlinlang.org/t/long-type-hex-error/4310>\
**Category:** Uncategorized\
**Created:** [August 23, 2017, 9:02am UTC](https://discuss.kotlinlang.org/t/long-type-hex-error/4310 "2017-08-23T09:02:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangmengxiong](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zhangmengxiong](https://discuss.kotlinlang.org/u/zhangmengxiong)\
**Post date:** [August 23, 2017, 9:02am UTC](https://discuss.kotlinlang.org/t/long-type-hex-error/4310/1 "2017-08-23T09:02:27Z")

</div>

I got a error in Type of Long (hex)

convert it to decimal is OK

it’s a problem?

> ```
> private val POLY64REV: Long = 0x95AC9329AC4BC9B5L
> private val INITIALCRC: Long = 0xFFFFFFFFFFFFFFFFL
> 
> ```

![图片](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/c/c54821a52595cb5b9dc3765b79a3ca1342088c9b.png)

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [August 23, 2017, 9:56am UTC](https://discuss.kotlinlang.org/t/long-type-hex-error/4310/2 "2017-08-23T09:56:30Z")

</div>

The problem is that Long type in both Kotlin and Java is a **signed** 64-bit integer and so the values you’re trying to assign to those variables are indeed out of range.

However, it is very likely that **unsigned** types will be introduced into the language in the not too distant future which will solve your problem. In the meantime you could use the BigInteger type as a workaround as this can deal with integers of arbitrary size.

---

<div class="post-metadata">

**Author:** ![zhangmengxiong](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zhangmengxiong](https://discuss.kotlinlang.org/u/zhangmengxiong)\
**Post date:** [August 24, 2017, 6:23am UTC](https://discuss.kotlinlang.org/t/long-type-hex-error/4310/3 "2017-08-24T06:23:07Z")

</div>

![图片](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/f/f6ced58deedacf69f06f90c1941ef9eaadcff9ea.png)

The same code in Java is right

Kotlin version

> ext.kotlin\_version = ‘1.1.4-2’

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [August 24, 2017, 6:44am UTC](https://discuss.kotlinlang.org/t/long-type-hex-error/4310/4 "2017-08-24T06:44:08Z")

</div>

As stated by @alanfo, the values you use are out of range of **unsigned** 64-bit integers. You can use a simple function to do what you want:

```
fun unsignedLong(mostSignificantBits: Long, leastSignificantBits: Long) =
        (mostSignificantBits shl 32) or leastSignificantBits

```

Note that there is no check that only bits in the lower 32 are set in the parameters, but a few additional checks will solve that.

This results in the following code, which is a bit more verbose but still easy to read:

```
private val POLY64REV: Long = unsignedLong(0x95AC9329, 0xAC4BC9B5)
private val INITIALCRC: Long = unsignedLong(0xFFFFFFFF, 0xFFFFFFFF)

```

If you want a shorter, less cluttered notation you could try an infix extension function.
