# Experimental unsigned values

**URL:** <https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037>\
**Category:** Support\
**Created:** [October 14, 2016, 11:43am UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037 "2016-10-14T11:43:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elect](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@elect](https://discuss.kotlinlang.org/u/elect)\
**Post date:** [October 14, 2016, 11:43am UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/1 "2016-10-14T11:43:46Z")

</div>

I am trying to experiment if I can get unsigned in a more confortable way…

I followed all the instructions to build Kotlin from source

then I modified

[`\core\builtins\native\kotlin\Primitives.kt`](https://github.com/JetBrains/kotlin/blob/1.1-M1/core/builtins/native/kotlin/Primitives.kt#L25)

and removed the `private` from the declaration

`public class Byte () : Number, Comparable<Byte> {`

I also removed it from

[`\generators\src\builtins\primitives.kt`](https://github.com/JetBrains/kotlin/blob/1.1-M1/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt#L68)

Ps: what’s the difference between these two files exactly?

And then I built. Therefore I substitued all the jars under

`$HOME\.IdeaIC2016.2\config\plugins\Kotlin`

with the ones I got from the build

I wrote:

```
fun main(args: Array<String>) {

    class Test : Int() {

    }
}

```

But I get

> Error:(26, 18) Kotlin: This type is final, so it cannot be inherited from  
> Error:(26, 18) Kotlin: Cannot access ‘\< init\>’: it is private in ‘Int’

Is there a way I can solve this?

How/when/where will be actually declared the operator overloads of the primitives?

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [October 14, 2016, 11:51am UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/2 "2016-10-14T11:51:34Z")

</div>

Primitive types are compiled to JVM primitive values, and the operators on primitive types are compiled to direct invocations of the corresponding JVM bytecodes.The JVM does not support unsigned primitive types. You could solve this if you wanted to invest multiple months of your time in learning the details of the Kotlin compiler internals, the JVM implementation and working together with the Kotlin team to design and implement this feature.

---

<div class="post-metadata">

**Author:** ![elect](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@elect](https://discuss.kotlinlang.org/u/elect)\
**Post date:** [October 14, 2016, 1:12pm UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/3 "2016-10-14T13:12:32Z")

</div>

Thanks for the explanation, yole

I wish I had the time, because I’d be interesting to learn all those stuff

However for the moment what I would like to have is another class, let’s say Uint, that acts exactly as a normal int, but with some of its operator overloaded, such as the division.

Will it work if I declare it in the same file `Primitives.kt` and overwrite/declare only those operators?

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [October 14, 2016, 1:14pm UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/4 "2016-10-14T13:14:40Z")

</div>

No, this will not work. Once again: implementing something like this is a multiple-month project.

---

<div class="post-metadata">

**Author:** ![elect](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@elect](https://discuss.kotlinlang.org/u/elect)\
**Post date:** [October 14, 2016, 1:21pm UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/5 "2016-10-14T13:21:22Z")

</div>

Uhm, ok.

I can’t offer much, since I lack time and skill (I know almost nothing about compilerish stuff and I just started learning kotlin), but I’d like to give anyway my 2 cent availability for this long-term project

Where could we start from?

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [October 14, 2016, 1:37pm UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/6 "2016-10-14T13:37:29Z")

</div>

Please start with establishing a thorough understanding of how existing primitive types work in Java and in Kotlin, on the level of the type system and bytecode. After that, please read [http://docs.scala-lang.org/sips/completed/value-classes.html](http://docs.scala-lang.org/sips/completed/value-classes.html) and watch Brian Goetz’ talks on Project Valhalla from the JVM Language Summit.

---

<div class="post-metadata">

**Author:** ![elect](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@elect](https://discuss.kotlinlang.org/u/elect)\
**Post date:** [October 21, 2016, 8:07am UTC](https://discuss.kotlinlang.org/t/experimental-unsigned-values/2037/7 "2016-10-21T08:07:06Z")

</div>

In the meanwhile, I wrote [this small util](https://github.com/elect86/kotlin-unsigned) for boxed unsigned types and unsigned operations on primitives
